encode

Summary

Encodes a string of text using UTF-16 encoding.

Usage

public static byte[] encode(string text)

Returns

A byte sequence representing the input text encoded with UTF-16.

Parameters

text

The text to encode.

Description

Encodes a string of text using UTF-16 encoding.

The order of the encoded bytes are little endian, and all encoded byte sequences are prefixed with the little endian byte order mark (BOM): 0xFF + 0xFE.

Examples

Basic Usage
1
2
3
4
5
6
7
8
9
10
11
import System;
import System.Encoding;
  
byte[] encoded = UTF16.encode("�");
  
string toHex = "";
foreach(byte b in encoded) {
    toHex += "\\x" + b.toHex().toUpperCase();
}
  
Console.log(toHex); // "\xFF\xFE\xAC\x20"

Share

HTML | BBCode | Direct Link