Hi,
There is a string in unicode. The length of Latin characters is 1 byte, the length of characters of other code pages is 2 bytes.
How to get an array of characters of this string ?
String in unicode
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: String in unicode
This is a UTF8 encoded string.
You can use HB_UTF8LEN( cString ) to find the number of characters (not bytes) and HB_UTF8SUBSTR( cString, n, 1 ) to get the nth character (not byte)
Example:
Let us take a sample string in Hex: "41C39CC49EE0B095".
This is displayed as : AÜĞక
![Image](https://imagizer.imageshack.com/v2/xq70/923/VRA7nh.png)
You can use HB_UTF8LEN( cString ) to find the number of characters (not bytes) and HB_UTF8SUBSTR( cString, n, 1 ) to get the nth character (not byte)
Example:
Let us take a sample string in Hex: "41C39CC49EE0B095".
This is displayed as : AÜĞక
Code: Select all | Expand
#include "fivewin.ch"
function Main()
local cString := HEXTOSTR( "41C39CC49EE0B095" )
local nChars, n
local aChars := {}
? cString // --> AÜĞక
? "Length in Bytes : ", Len( cString ) // --> 8
? "Length in Chars : ", nChars := HB_UTF8LEN( cString ) --> 4
for n := 1 to nChars
aAdd( aChars, HB_UTF8SUBSTR( cString, n, 1 ) )
next
XBROWSER aChars // { "A", "Ü", "Ğ", "క" }
AEval( aChars, { |c,i| aChars[ i ] := { c, STRTOHEX( c ), Len( c ) } } )
XBROWSER aChars SETUP oBrw:cHeaders := { "CHAR","HEX","BYTES" }
return nil
![Image](https://imagizer.imageshack.com/v2/xq70/923/VRA7nh.png)
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: String in unicode
For me, these two sources are helpful regarding UTF8:
1. 3.5 Codepage API - UTF8 and code page functions built into Harbour: http://www.kresin.ru/en/hrbfaq_3.html#Doc5
2. Unicode conversion functions for Harbour. http://www.hmgextended.com/files/CONTRI ... onvert.prg unfortunately no longer online![Sad :(](./images/smilies/icon_sad.gif)
Maybe someone can help
![Wink :wink:](./images/smilies/icon_wink.gif)
1. 3.5 Codepage API - UTF8 and code page functions built into Harbour: http://www.kresin.ru/en/hrbfaq_3.html#Doc5
2. Unicode conversion functions for Harbour. http://www.hmgextended.com/files/CONTRI ... onvert.prg unfortunately no longer online
![Sad :(](./images/smilies/icon_sad.gif)
Maybe someone can help
![Cool 8)](./images/smilies/icon_cool.gif)
![Wink :wink:](./images/smilies/icon_wink.gif)
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
Re: String in unicode
muchas gracias Antonio ![Cool 8)](./images/smilies/icon_cool.gif)
![Cool 8)](./images/smilies/icon_cool.gif)
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86