fromCharCode() method

The fromCharCode() method in Apps Script is used to convert a Unicode value into a character. It returns a string representing the character corresponding to the specified Unicode value.

Example 1: Converting a Unicode Value to a Character
Suppose we have a Unicode value 65, which corresponds to the character “A”. We can use the fromCharCode() method like so:

var uniValue = 65;
var char = String.fromCharCode(uniValue);
Logger.log(char);

In this example, we define a Unicode value 65 and use the fromCharCode() method to convert it to the character “A”. The method returns a value of “A”, which is logged to the console.

Example 2: Converting Multiple Unicode Values to Characters
Suppose we have a list of Unicode values corresponding to the first letters of some cities, like so: [78, 89, 80, 84]. We want to convert these values to the corresponding characters to form the string “NYPT”. We can use the fromCharCode() method in a loop like so:

var unicodeValues = [78, 89, 80, 84];
var str = "";
for (var i = 0; i < unicodeValues.length; i++) {
  str += String.fromCharCode(unicodeValues[i]);
}
Logger.log(str);

In this example, we define an array unicodeValues containing the Unicode values corresponding to the first letters of some cities. We use a for loop to iterate over the array and use the fromCharCode() method to convert each value to the corresponding character. The resulting characters are concatenated to form the string “NYPT”, which is logged to the console.

By using the fromCharCode() method in Apps Script, we can easily convert Unicode values to their corresponding characters, and use the resulting characters to perform various operations on strings.