N/encode Module Script Samples
The following script sample demonstrates how to use the features of the N/encode module.
Convert a String to a Different Encoding
The following script shows how to convert a string to a different encoding.
Note:
This sample script uses the require
function so that you can copy it into the SuiteScript Debugger and test it. You must use the define
function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.
/**
* @NApiVersion 2.x
*/
require(['N/encode'], function(encode) {
function convertStringToDifferentEncoding() {
var stringInput = "Tést Striñg Input";
var base64EncodedString = encode.convert({
string: stringInput,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
});
var hexEncodedString = encode.convert({
string: stringInput,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.HEX
});
}
convertStringToDifferentEncoding();
});