How to convert a string to ASCII

harishdasari
Tera Guru

Hello,

We have requirement to convert string to ASCII values.

for example: "hello " is the string which needs to be converted to ASCII value 72,69,76,76,79

Thank you.

1 ACCEPTED SOLUTION

Vishal Khandve
Kilo Sage
var string = "Some string";

for (var i = 0; i < string.length; i++) {
  console.log(string.charCodeAt(i));
}

View solution in original post

7 REPLIES 7

Sunil B N
ServiceNow Employee
ServiceNow Employee

you can make use of charCodeAt

var str = "hello servicenow";
str.charCodeAt(0); //give ASCI of character at index 0.

You can run either run a loop and capture for all characters in string.

Cheers,
Sunil B N
P.S: If this is useful, please mark this as an answer/helpful.

Vishal Khandve
Kilo Sage
var string = "Some string";

for (var i = 0; i < string.length; i++) {
  console.log(string.charCodeAt(i));
}

HI Vishal and Sunil,

 

How to remove "" from a string in a business rule as this is called in a rest message and it is giving incorrect JSON payload.

harishdasari
Tera Guru

Thank you so much Sunil and Vishal.

Both answers are correct.