Difference between revisions of "ConvertEncoding"

From Xojo Documentation

m (Notes)
m
Line 7: Line 7:
 
|text = Provides a quick way to convert a string of known encoding to some other encoding, without having to create a [[TextConverter]] object. }}
 
|text = Provides a quick way to convert a string of known encoding to some other encoding, without having to create a [[TextConverter]] object. }}
  
 
+
==Syntax==
=='''Syntax'''==
 
 
''result'' = '''ConvertEncoding'''(''Str'', ''NewEncoding'')<br />
 
''result'' = '''ConvertEncoding'''(''Str'', ''NewEncoding'')<br />
 
'''OR'''<br />
 
'''OR'''<br />
Line 40: Line 39:
 
|}
 
|}
  
=='''Notes'''==
+
==Notes==
 
When you need to write text to a file that will be opened by another application that expects a particular encoding, use '''ConvertEncoding''' to convert the text to that encoding before you call the Write method. Here is an example that converts the text in a [[TextField]] to the MacRoman encoding.
 
When you need to write text to a file that will be opened by another application that expects a particular encoding, use '''ConvertEncoding''' to convert the text to that encoding before you call the Write method. Here is an example that converts the text in a [[TextField]] to the MacRoman encoding.
  
Line 54: Line 53:
 
</rbcode>
 
</rbcode>
  
=='''Example'''==
+
==Example==
 
The following example use the [[Encodings]] module to convert the text in a [[TextField]] to the ANSI encoding:
 
The following example use the [[Encodings]] module to convert the text in a [[TextField]] to the ANSI encoding:
  
Line 62: Line 61:
 
</rbcode>
 
</rbcode>
  
=='''See Also'''==
+
==See Also==
 
[[TextConverter]], [[TextEncoding]], [[TextOutputStream]] classes; [[DefineEncoding]], [[Encoding]] functions; [[Encodings]] module.
 
[[TextConverter]], [[TextEncoding]], [[TextOutputStream]] classes; [[DefineEncoding]], [[Encoding]] functions; [[Encodings]] module.
  
 
[[Category:Text_Text_Encoding]]
 
[[Category:Text_Text_Encoding]]

Revision as of 16:09, 26 July 2017

Method

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

Syntax

result = ConvertEncoding(Str, NewEncoding)
OR
result = Str.ConvertEncoding(NewEncoding)

Part Type Description
result String The converted string using the NewEncoding TextEncoding.
str String The string to be converted.
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 application that expects a particular encoding, use ConvertEncoding to convert the text to that encoding before you call the Write method. Here is an example that converts the text in a TextField to the MacRoman encoding.

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

Example

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

Dim s As String
s = ConvertEncoding(TextField1.Text, Encodings.WindowsANSI)

See Also

TextConverter, TextEncoding, TextOutputStream classes; DefineEncoding, Encoding functions; Encodings module.