vb script - replace and hex

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DevInCode
    New Member
    • Apr 2008
    • 55

    vb script - replace and hex

    Hi.
    I'm extracting dates from a file and I've found something that seems very inconsistent.

    I print to the console when I find what I am looking for. Then I attempt to split the value I found. The first example processes without incident.

    19 Mai 2006

    After a few more successful finds I hit this:

    1 mars 2006

    Then when I try and split it by space and call the split_value(2) its out of bounds, and upon further investigation I see that split_value(0) is 1 mars 2006

    I also print the values to a log file. When I copy and paste them into notepad++ and covert them to hex, this is what I get:

    31 39 20 6D 61 69 20 32 - 30 30 36 20

    and

    31 A0 6D 61 72 73 A0 - 32 30 30 35 20

    The most obvious thing is the difference in space characters.

    This was for work and it appears I might have written something down wrong. Anyway if you have any suggestions as to how I can work around this I'd love to hear them.

    Thanks!
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    yeap, what you say is right, the ASCII code for [space] is 32
    but in the 2nd one, you're using 160 (A0 in hex)

    so if you see, this will give you twice the same result:

    [CODE=vb]Sub SpaceTest()
    MsgBox "a" & Chr(32) & "a"
    MsgBox "a" & Chr(160) & "a"
    End Sub[/CODE]

    Replace before parsing the string seems like a good solution:

    [CODE=vb]replace(str1, chr(160), chr(32))
    split_array = split(str1,chr( 32))[/CODE]

    HTH

    Comment

    Working...