Android Question Need convert HEX string to Symbols

Juanll2003uy

Member
Licensed User
Hi, i receive by webservice an string wich have hexadecimal string.
I need to convert it to the symbol string to send to print.

hex.txt is that i receive and cfe.txt is the result that i need.

I saw some examples here with ByteConverter but i couldnt do it.

Someone can help me with this?

Thanks
 

Attachments

  • hex.txt
    111.3 KB · Views: 177
  • cfe.txt
    32.2 KB · Views: 156

Sandman

Well-Known Member
Licensed User
I would use regex.split. First split on &# to get each chunk with hex code and potentially trailing non-hex text. Then iterate over that list, and on each chunk another regex.split, this time on the ;. First match will be the hexcode that you need to convert to a char, and if there's another match, that's just pure text to add.
 
Upvote 0

Juanll2003uy

Member
Licensed User
Hi Sandman, i have tried with this code, to find all the hex elements and try to convert to symbol
But when the hex is for example "�" it crush in bconv.HexToBytes("�")
And the symbols that i receive arent the correct in the string :(
I dont know if the functions that i use are the correct to it

B4X:
            i=PrintBuffer.IndexOf("&#")
            j=PrintBuffer.IndexOf2(";",i)
            Do While i >= 0
                bytearray=Null
                bytearray = bconv.HexToBytes(PrintBuffer.SubString2(i,j+1))
                PrintBuffer=PrintBuffer.Replace(PrintBuffer.SubString2(i,j+1), bconv.StringFromBytes(bytearray, "UTF8"))

                i=PrintBuffer.IndexOf("&#")
                j=PrintBuffer.IndexOf2(";",i)
            Loop
 
Last edited:
Upvote 0

Sandman

Well-Known Member
Licensed User
First of all, delete your duplicate post, and wrap your code in code tags before Erel or DonManfred sees you.

upload_2018-7-12_22-6-6.png


Your code seems overly complicated. Give regex.split a shot, and don't do any replacing in the hex.txt file, just build a new file.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
This does not appear to be any standard byte encoding scheme that I am familiar with. Where is this data coming from? I'm guessing that whatever is sending it should tell you how to interpret it in their SDK or API documentaion.
 
Upvote 0

Juanll2003uy

Member
Licensed User
Yes, but it dont work because i need convert HEX to Symbol before

 into SCAPE
 INTO Data Link Escape
� INTO Null

For example

But i dont find the way
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Last edited:
Upvote 0

Similar Threads

Top