Encoding

From Real Software Documentation

Jump to: navigation, search
Method

Returns the text encoding of the passed String.


Syntax

result=Encoding(str)
OR
result=str.Encoding

Part Type Description
result TextEncoding The text encoding of str.
str String The string whose TextEncoding will be returned.

Notes

Use the Encoding function to determine the encoding of a string. This is useful for text that you have read in from an external source, for example, with TextInputStream and you don’t know the encoding. For text that is generated within Real Studio, the encoding is known to Real Studio.

If the string's encoding is unknown, Encoding returns Nil. Test whether the TextEncoding object is Nil or include an Exception block if there is a chance the string’s encoding would not be known at runtime.

Examples

The following example gets the encoding of the text stored in the local variable, s. The Exception block handles the call to one of the TextEncoding object's properties if the encoding cannot be determined or the file cannot be opened.

Dim f As FolderItem
Dim t As TextInputStream
Dim s As String
Dim enc as TextEncoding
f=GetOpenFolderItem("text") //file type defined via the FileType class
If f <> Nil then
t=TextInputStream.Open(f)
s=t.ReadAll
t.Close
End if
enc=s.Encoding
Exception err as NilObjectException
MsgBox err.message


See Also

TextConverter, TextEncoding, TextInputStream classes; ConvertEncoding, DefineEncoding, GetTextEncoding functions; Encodings module.

Personal tools