admin管理员组文章数量:1414614
I have a string value like 1,2,3
and i need convert to byte value like [1,2,3]
?
how to bind javascript byte to C# Byte[]
array
const file = e.files[0];
var reader = new FileReader();
reader.readAsArrayBuffer(file.rawFile);
reader.onload = function () {
var strBytes = new Uint8Array(reader.result).join();
var byte=???;
}
thanks
I have a string value like 1,2,3
and i need convert to byte value like [1,2,3]
?
how to bind javascript byte to C# Byte[]
array
const file = e.files[0];
var reader = new FileReader();
reader.readAsArrayBuffer(file.rawFile);
reader.onload = function () {
var strBytes = new Uint8Array(reader.result).join();
var byte=???;
}
thanks
Share Improve this question edited Jul 17, 2017 at 6:28 Koby Douek 16.7k20 gold badges78 silver badges110 bronze badges asked Jul 17, 2017 at 6:23 Hossein HaghHossein Hagh 1272 gold badges3 silver badges15 bronze badges 1-
2
.join()
converts theUint8Array
to a string. If you don’t want a string, don’t call.join()
. – Ry- ♦ Commented Jul 17, 2017 at 6:24
1 Answer
Reset to default 0When creating a Uint8Array
, the data is stored as bytes, which is exactly what you are looking for here.
What you've done when using .join()
is to create them as strings.
Just remove the .join
and you will have an array of bytes:
var strBytes = new Uint8Array(reader.result);
本文标签: how to convert string to bytes in javascriptStack Overflow
版权声明:本文标题:how to convert string to bytes in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745178793a2646367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论