I want to convert string from ascii to hexadecimal
I tried:
var stringing = "";
jQuery.each("SomeText".split(""), function (i, data) {
stringing = stringing + data.charCodeAt(0)
});
But this output is not the same as what I get at /
I need to get the same values because only that works in KQL in sharepoint
I want to convert string from ascii to hexadecimal
I tried:
var stringing = "";
jQuery.each("SomeText".split(""), function (i, data) {
stringing = stringing + data.charCodeAt(0)
});
But this output is not the same as what I get at http://www.asciitohex./
I need to get the same values because only that works in KQL in sharepoint
Share Improve this question edited Nov 25, 2015 at 15:50 CoderPi 13.2k4 gold badges38 silver badges64 bronze badges asked Nov 25, 2015 at 15:22 Vignesh SubramanianVignesh Subramanian 7,30914 gold badges96 silver badges158 bronze badges 1- I tried this var something="text"; console.log(something.toString(16)), but it didn't work – Vignesh Subramanian Commented Nov 25, 2015 at 15:26
2 Answers
Reset to default 6How about
String.prototype.convertToHex = function (delim) {
return this.split("").map(function(c) {
return ("0" + c.charCodeAt(0).toString(16)).slice(-2);
}).join(delim || "");
};
and
"SomeText".convertToHex();
// -> "536f6d6554657874"
"SomeText".convertToHex(" ");
// -> "53 6f 6d 65 54 65 78 74"
Note that this will fail with Unicode characters. Use it for ASCII/ANSI input only.
You can also use Buffer to convert ascii to hex
let hex = Buffer('Some Text', 'ascii').toString('hex');
console.log(hex);