DefineEncoding

From Xojo Documentation
Jump to: navigation, search
Method

Returns a String with the same data as the given string, but with the encoding of the passed encoding.

Notes

This function is useful when you have a string whose encoding is known to you but not to your application. The encoding of all strings created in your application is UTF-8, so you don't have to use DefineEncoding on them.


Syntax

result=DefineEncoding(str, enc)
OR
result=str.DefineEncoding(enc)

Part Type Description
result String The result of encoding str using the encoding specified by enc.
str String The String to be encoded.
enc TextEncoding The TextEncoding to be used to encode str.

Notes

Consult the values of Base entry for TextEncoding when creating the TextEncoding object using the GetTextEncoding function.

Examples

The following example takes 8 bytes from a MemoryBlock and sets the encoding to UTF16.

TextField1.Text = DefineEncoding(MyMemoryBlock.StringValue(0, 8), Encodings.UTF16)


This example uses DefineEncoding when reading text via a TCPSocket.

TexField1.Text = DefineEncoding(TCPSocket1.ReadAll, Encodings.ASCII)

See Also

TextEncoding class; ConvertEncoding, Encoding, GetTextEncoding functions; Encodings module.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About