cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Unicode strings

Former Member
0 Kudos

I am getting a string from an external source (not a text file) that sends text as Ascii with Unicode characters encoded like this:

U+C218U+C815U+AC74

I need a method to convert this to the Unicode encoding format used by normal PowerBuilder string variables.

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Roland,

it looks like "Unicode U+hex notation". Unicode code converter

Here is a native2ascii converter: Native-to-ASCII Converter (Online: Interactive native2ascii)

Maybe this Java code can help you to write your own converter: ASCII 2 NATIVE : Code Unicode « Development Class «&...

Former Member
0 Kudos

I need to convert the Hex number to a Long and then feed it into the Char function to get the Unicode character. Then I need to replace the U+#### in the string with the char.

Former Member
0 Kudos

Hi Roland;

  If it helps ...  you are welcome to use my fn_long2hex ( ) and fn_hex2long ( ) functions as well as the find & replace features of my STD Framework to get the job done.

Regards ... Chris

Former Member
0 Kudos

Already have them, thanks.

Here is what I came up with:

String ls_comment, ls_code, ls_char

Long ll_pos, ll_char

ls_comment = "Some regular text with U+C218U+C815U+AC74 embedded unicode."

ll_pos = Pos(ls_comment, "U+")

Do While ll_pos > 0

     ls_code = Mid(ls_comment, ll_pos + 2, 4)

     ll_char = of_Hex2Nbr(ls_code)

     ls_char = String(Char(ll_char))

     ls_comment = Replace(ls_comment, ll_pos, 6, ls_char)

     ll_pos = Pos(ls_comment, "U+", ll_pos)

Loop

MessageBox("Comment", ls_comment)

Former Member
0 Kudos

Hi Chris

can you send me the code function fn_long2hex ( ) and fn_hex2long ( ).

Thanks a lot.

André Rust

Former Member
0 Kudos

Hi Andre;

  You can just download the framework and then extract those global functions. There are many others that might interest you as well. The framework is free to use or borrow code from.

FYI:  http://sourceforge.net/projects/stdfndclass/

Regards ... Chris

PS: Let me know if you cannot access SourceForge.

Former Member
0 Kudos

Hi Chris ,

Thanks. I have downloaded.

André Rust