最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to convert string to bytes in javascript - Stack Overflow

programmeradmin2浏览0评论

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 the Uint8Array to a string. If you don’t want a string, don’t call .join(). – Ry- Commented Jul 17, 2017 at 6:24
Add a ment  | 

1 Answer 1

Reset to default 0

When 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);
发布评论

评论列表(0)

  1. 暂无评论