Newer Version Available
EncodingUtil Class
Namespace
Usage
EncodingUtil Methods
The following are methods for EncodingUtil. All methods are static.
convertFromHex(inputString)
Signature
public static Blob convertFromHex(String inputString)
Parameters
- inputString
- Type: String
- The hexadecimal string to convert. The string can contain only valid hexadecimal characters (0-9, a-f, A-F) and must have an even number of characters.
Return Value
Type: Blob
Usage
Each byte in the Blob is constructed from two hexadecimal characters in the input string.
The convertFromHex method throws the following exceptions.
- NullPointerException — the inputString is null.
- InvalidParameterValueException — the inputString contains invalid hexadecimal characters or doesn’t contain an even number of characters.
Example
1Blob blobValue = EncodingUtil.convertFromHex('4A4B4C');
2System.assertEquals('JKL', blobValue.toString());convertToHex(inputBlob)
Signature
public static String convertToHex(Blob inputBlob)
Parameters
- inputBlob
- Type: Blob
Return Value
Type: String
urlDecode(inputString, encodingScheme)
Signature
public static String urlDecode(String inputString, String encodingScheme)
Return Value
Type: String
Usage
This method uses the supplied encoding scheme to determine which characters are represented by any consecutive sequence of the from \"%xy\". For more information about the format, see The form-urlencoded Media Type in Hypertext Markup Language - 2.0.
urlEncode(inputString, encodingScheme)
Signature
public static String urlEncode(String inputString, String encodingScheme)
Return Value
Type: String
Usage
This method uses the supplied encoding scheme to obtain the bytes for unsafe characters. For more information about the format, see The form-urlencoded Media Type in Hypertext Markup Language - 2.0.
Example
1String encoded = EncodingUtil.urlEncode(url, 'UTF-8');