encode.convert(options)

Method Description

Converts a string to another type of encoding.

Returns

The re-encoded string.

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/encode Module

Since

2015.1

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.string

string

required

The string to encode.

2015.1

options.inputEncoding

string

required

The encoding used for the input string.

Use encode.Encoding to set the value.

2015.1

options.outputEncoding

string

required

The encoding to apply to the output string.

If set to UTF-8 and the input string does not contain a valid UTF-8 encoded string, the operation will continue but the resulting string will contain the replacement character U+FFFD.

Use encode.Encoding to set the value.

2015.1

Errors

Error Code

Thrown If

FAILED_TO_DECODE_STRING_ENCODED_BINARY_DATA_USING_1_ENCODING

The value of the options.string parameter does not represent binary data encoded using the encoding specified by the options.inputEncoding parameter.

SSS_MISSING_REQD_ARGUMENT

Any of the options.string, options.inputEncoding, or options.outputEncoding parameters are not provided.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/encode Module Script Samples.

            //Add additional code 
...
var hexEncodedString = encode.convert({
    string: stringInput,
    inputEncoding: encode.Encoding.UTF_8,
    outputEncoding: encode.Encoding.HEX
});
...
//Add additional code 

          

Related Topics

General Notices