Dan O
Dan O

Reputation: 6090

how do I add an arbitrary byte value onto the end of a string? (JavaScript)

in JavaScript, how do I add an arbitrary byte value onto the end of a string? I'm trying to construct an array which contains both ASCII and binary data, for passing to a remote server. I tried String.fromCharCode() but that only seems to work for bytes from 0x00 to 0x7f inclusive - larger byte values get turned into two-byte characters (which all makes sense now that I think about it).

Thanks in advance -

Upvotes: 4

Views: 2257

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385194

var myString = "Hello world";
myString += "\x21";
alert(myString);

Or, for a less canonical string that nonetheless demonstrates the range:

var myString = "Hello world";
myString += "\xE9";
alert(myString);

Upvotes: 4

Related Questions