Method

ConvertEncoding


Description

Provides a quick way to convert a string of known encoding to some other encoding, without having to create a TextConverter object.

Usage

result = sourceVariable.ConvertEncoding(newEncoding)

Part

Type

Description

result

String

The converted string using the NewEncoding TextEncoding.

sourceVariable

String

The string to be converted. It must already have an encoding. Use DefineEncoding to set an encoding.

newEncoding

TextEncoding

The encoding to be used in the conversion.

Notes

When you need to write text to a file that will be opened by another app that expects a particular encoding, use ConvertEncoding to convert the text to that encoding before you call the Write method.

The string must already have an encoding in order to convert it to something else. Use DefineEncoding to set an encoding if it does not have one.

Sample code

The following code use the Encodings module to convert the text in a TextField to the ANSI encoding:

Var result As String
result = TextField1.Text.ConvertEncoding(Encodings.WindowsANSI)

Here is an example that converts the text in a TextField to the MacRoman encoding.

Var f As FolderItem
Var fileStream As TextOutputStream
file = FolderItem.SaveFileDialog(FileTypes1.Text, "My Info.txt")
If f <> Nil Then
  fileStream = TextOutputStream.Create(f)
  fileStream.Write(nameField.Text.ConvertEncoding(Encodings.MacRoman))
  fileStream.Close
End If

Compatibility

All project types on all supported operating systems.