Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASCII character as delimiter in txt file (.NET framework 1.1)

    Dear Loungers,
    I'm reading a text file generated by legacy app, and writing code to parse it into fields. The file uses a delimiter that cannot by typed at the keyboard, so it appears as a weird-looking character in the stream. The legacy programmer says its "~001".

    // this does not work
    string [] HoursWorkedFields = System.Text.RegularExpressions.Regex.Split(line,"0 1");

    This is what is returns (paste from Immediate window): ? HoursWorkedFields[0]

    "00065ALLAM2510197300 40.00"

    How can I represent the  character as a delimiter? How can I test a char to find out what its ASCII code is?

    Any help gratefully received,

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ASCII character as delimiter in txt file (.NET framework 1.1)

    The Microsoft.VisualBasic namespace gives you access to the Chr() function. Try Chr(001) as your delimiter. You can also try Chr(1) and Chr(01), both of which also produce the box character. You may have to experiment to figure out the right ascii code to use for the specific delimiter used in the legacy app, since it isn't as easy to back into in .Net as it is in VB/VBA.
    Charlotte

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASCII character as delimiter in txt file (.NET framework 1.1)

    Hi Gwenda,

    Several thoughts come to mind:
    1) Since you have access to the legacy programmer, do you also have access to the legacy source code? If so, that *may* be of some use to finding the exact characters of the mystery delimiter.

    2) The  character is not a specific characeter. It's often used when the actual character can not be displayed for whatever reason. I'm not sure exactly what the reason is, but I often see this character in database text fields representing a line break/carriage return when viewing the raw data in a table.

    2) You can possibly determine the string value by isolating the characters in question and using the following code snippet:<pre> 'Note: This is very crude, but will return the ascii characters for any given string
    Function GetAsciiCharacterCode(ByVal input As String) As String
    Dim returnString As String 'String to return
    Dim encodingObject As System.Text.Encoding = System.Text.Encoding.Default 'Encoding object

    'Get byte array from input string
    Dim encodedArray As Byte() = encodingObject.GetBytes(input)
    Dim b As Byte 'Byte object used for iteration

    'For each byte in encodedArray
    For Each b In encodedArray
    'Append byte's string value to return string
    returnString &= b.ToString() & Environment.NewLine
    Next

    'return
    Return returnString
    End Function</pre>


    This will return a string of the Ascii character codes separated by line breaks.

    Let me know if you have any questions or problems with this. Hope this helps!

  4. #4
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASCII character as delimiter in txt file (.NET framework 1.1)

    Thanks MarkJ and Charlotte, I'll try these ideas and let you know how it works.

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ASCII character as delimiter in txt file (.NET framework 1.1)

    Hi Mark and Charlotte,
    I talked to the legacy programmer and confirmed that the ASCII delimiter was 01 (that was a good idea Mark). Then investigating Regular Expressions a bit more, I found that I needed to include an "x" after the "" escape code to indicate that an ASCII character follows. So this now works:

    string [] HoursWorkedFields = System.Text.RegularExpressions.Regex.Split(line,"x 01");

    Regular Expressions are wicked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •