Hi All,
May I have some code in HMG to Converts UTF-8 characters in cExpression to double-byte characters.
Regards,
STRCONV function in HMG
Moderator: Rathinagiri
- Jairo Maia
- Posts: 53
- Joined: Sun Jul 17, 2011 1:47 pm
- Location: Campinas - SP - Brazil
Re: STRCONV function in HMG
Harbour 2.1 or later, have support for UTF-8. There are two functions for conversion:
Hb_UTF8ToStr( cString ) // convert a UTF-8 string to OEM
Hb_StrToUTF8( cString ) // convert a OEM string to UTF-8
Hb_UTF8ToStr( cString ) // convert a UTF-8 string to OEM
Hb_StrToUTF8( cString ) // convert a OEM string to UTF-8
Re: STRCONV function in HMG
Hi Jairo Maia,
Thank you very much.
Regards,
Apichit
Thank you very much.
Regards,
Apichit
- Jairo Maia
- Posts: 53
- Joined: Sun Jul 17, 2011 1:47 pm
- Location: Campinas - SP - Brazil
Re: STRCONV function in HMG
Hi Apichit,
If you need to identifi a coding of the a string, you can to use this function:
If you need to identifi a coding of the a string, you can to use this function:
Code: Select all
/*
* This function return the coding of the String.
*
* You can change as desired, but, the sequence UTF8, ANSI and OEM must
* be maintained for the function work properly.
*
* Note: If the return is "DEFAULT", mean that the string have no
* special character.
*
* Copyright 2012 Jairo Maia <jairo.s.maia@gmail.com>
*/
Function IdCoding( cString ) // Identifies the coding of a string
Local i, cIdUtf := Chr( 195 )
Local aUtf := { 129, 130, 131, 132, 135, 137, 138, 141, 147, 148, ;
149, 150, 154, 156, 160, 161, 163, 162, 164, 167, ;
169, 170, 173, 179, 180, 181, 182, 186, 188 }
Local aAnsi := { 196, 193, 194, 195, 201, 202, 205, 211, 212, 213, ;
218, 220, 225, 227, 231, 234, 237, 243, 244, 245, ;
246, 250, 252 }
Local aOem := { 128, 129, 130, 131, 132, 133, 135, 136, 142, 144, ;
147, 148, 153, 154, 160, 161, 162, 163, 181, 182, ;
198, 229, 210 }
If Empty( cString ) .Or. ValType( cString ) != "C"
Return ("")
EndIf
For i = 1 To Len( aUtf )
If At( cIdUtf + Chr( aUtf[ i ] ), cString ) > 0
Return ( "UTF8" )
Endi
Next
For i = 1 To Len( aAnsi )
If At( Chr( aAnsi[ i ] ), cString ) > 0
Return ( "ANSI" )
Endi
Next
For i = 1 To Len( aOem )
If At( Chr( aOem[ i ] ), cString ) > 0
Return ( "OEM" )
Endi
Next
Return ( "DEFAULT" )Re: STRCONV function in HMG
Hi Jairo Maia,
You are so kind.
Thank you very much again.

You are so kind.
Thank you very much again.