Click or drag to resize

Ansi2Oem Function (String)

X#
Convert a string of ANSI characters to OEM characters.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax
 FUNCTION Ansi2Oem(
	cAnsiString AS STRING
) AS STRING
Request Example View Source

Parameters

cAnsiString
Type: String
A source string of ANSI characters.

Return Value

Type: String
A converted string of OEM characters.
Remarks
Ansi2Oem() changes the individual characters in the source string to matching characters from the OEM character set.
This may need to be done because certain symbols, such as ä, have different code values in the ANSI and OEM character sets. DOS applications creating a file with ä as part of the file name use the OEM code values and place 132 into the directory entry. But Windows applications with ANSI code values use 228 for ä and thus cannot find the file.
To get around this problem, you can use Ansi2Oem() to convert ANSI file names to the OEM character set. Also, if characters written to files by Windows applications are in the ANSI character set, the same character conversion problem might arise when DOS applications read the file.
Remarks
Caution note Caution
The Ansi2Oem() and Oem2Ansi() family of functions are compatibility functions. Do not use them unless you really have to. X# is a Unicode language and conversions from Unicode - Ansi - Oem - Unicode will take place if you use these functions.
You should also realize that Ansi2Oem(Oem2Ansi(cSource)) will not always return cSource. Some characters may not be available in the OEM codepage and could be translated to other characters. For example: Windows codepage 1252 has Capital E Umlaut (Ë) on position 203. When translated to OEM codepage 437 this will become capital E without umlaut (69). Converting back to Ansi this will remain a E without umlaut.
Examples
This example writes the string "aá.TXT" to a DOS file. Note that á has the code value 225 in the ANSI character set, while in the OEM character set, code value 225 corresponds to the ß character.
The FWrite() functions assume raw binary data and thus does not automatically convert ANSI to OEM. (If desired, you could do the conversion yourself or use other functions such as FWriteText().)
X#
1FWrite(ptrFileHandle, Ansi2Oem("aá.txt"))
See Also