Android Question Need convert HEX string to Symbols

Juanll2003uy

Member
Licensed User
Longtime 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: 305
  • cfe.txt
    32.2 KB · Views: 282

Sandman

Expert
Licensed User
Longtime 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
Longtime 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

Expert
Licensed User
Longtime User
First of all, delete your duplicate post, and wrap your code in code tags before Erel or DonManfred sees you.



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
Longtime 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

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Then the code may be a specific printer language, have you tried sending that string directly to the printer?
 
Upvote 0

Juanll2003uy

Member
Licensed User
Longtime 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
Longtime User
Last edited:
Upvote 0

Similar Threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…