Utf8FromStr - cCharTranslate

Creates a UTF-8 string in a memory buffer from a passed DataFlex string in OEM or ANSI format

Type: Function

Return Data Type: Pointer

Parameters: String sValue Integer eCharType

ParameterDescription
sValueThe string to convert
eCharTypeThe type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)


Return Value

The buffer address of the converted string


Syntax
Function Utf8FromStr String sValue Integer eCharType Returns Pointer

Call: Get Utf8FromStr sValue eCharType to PointerVariable


Description

Utf8FromStr creates a UTF-8 string in a memory buffer from an OEM or ANSI DataFlex string.

The length of the returned UTF-8 string may be obtained using CStringLength(). This returns the number of bytes in the string, which may not be the same as the number of characters in the string.

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 | UTF8ToStr | Free()