Utf8ToStr - cCharTranslate

Creates an OEM or ANSI string from a UTF-8 memory buffer

Type: Function

Return Data Type: String

Parameters: Pointer pWideBuf Integer eCharType

ParameterDescription
pWideBufThe address of a UTF-8 string
eCharTypeThe type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)


Return Value

The newly created DataFlex string


Syntax
Function Utf8ToStr Pointer pWideBuf Integer eCharType Returns String

Call: Get Utf8ToStr pWideBuf eCharType to StringVariable


Description

Utf8ToStr creates a OEM or ANSI DataFlex string from a UTF-16 memory buffer.

The length of the returned string may be obtained using Length().

You are responsible for eventually disposing of the newly created memory buffer.

Use Windows.pkg
Use cCharTranslate.pkg
 
Object oCharTranslate is a cCharTranslate
End_Object
 
// test Utf8FromStr and Utf8ToStr
Procedure TestUTF8Str
    Address aUTF8Buffer
    Integer iVoid
    String sVar sVar2

    Move "Test String-Ññóí" to sVar
    
    // Move OEM to UTF8 buffer
    Get Utf8FromStr of oCharTranslate sVar CP_OEMCP to aUTF8Buffer
    
    // Move UTF8Buffer to OEM String
    Get Utf8ToBuffer of oCharTranslate aUTF8Buffer CP_OEMCP to sVar2
    If (sVar<>sVar2) Begin
        Send Info_Box "Test Failed"
    End
    
    Move (Free(aUTF8Buffer)) to iVoid
End_Procedure
 
Send TestUTF8Str 

See Also

UTF8FromBuffer | UTF8ToBuffer | UTF8FromStr | Free()