Android Question Need convert HEX string to Symbols

Discussion in 'Android Questions' started by Juan Ignacio Llanes, Jul 12, 2018 at 8:06 PM.

  1. Juan Ignacio Llanes

    Juan Ignacio Llanes 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
     

    Attached Files:

    • hex.txt
      File size:
      111.3 KB
      Views:
      20
    • cfe.txt
      File size:
      32.2 KB
      Views:
      16
  2. Sandman

    Sandman Active 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.
     
  3. Juan Ignacio Llanes

    Juan Ignacio Llanes 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

    Code:
    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: Jul 12, 2018 at 9:43 PM
  4. Sandman

    Sandman Active 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.
     
    somed3v3loper likes this.
  5. Juan Ignacio Llanes

    Juan Ignacio Llanes Member Licensed User

    Thanks. I did it.
    Some idea to convert hex to the symbol?
    Any function?
     
  6. Jeffrey Cameron

    Jeffrey Cameron Active 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.
     
  7. Juan Ignacio Llanes

    Juan Ignacio Llanes Member Licensed User

    Ok thanks, it is a webservice that returns that string to send print.
     
  8. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Then the code may be a specific printer language, have you tried sending that string directly to the printer?
     
  9. Juan Ignacio Llanes

    Juan Ignacio Llanes 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
     
  10. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Ah, I understand now! The string you're getting is not byte encoded, it his HTML Encoded. I suggest you search here or on the web for HTML decoding a string.

    Edit: Perhaps you could make use of this as in-line java?
    https://code.i-harness.com/en/q/f2c1b
     
  11. Juan Ignacio Llanes

    Juan Ignacio Llanes Member Licensed User

    I think that arent html codes else hexadecimal codes
     
  12. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    Last edited: Jul 13, 2018 at 5:26 PM
    Juan Ignacio Llanes likes this.
  13. Juan Ignacio Llanes

    Juan Ignacio Llanes Member Licensed User

    It looks good!
    I will use it and tell you,
    thanks Cameron!
     
  14. Juan Ignacio Llanes

    Juan Ignacio Llanes Member Licensed User

    It works!
    Thank you for all!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice