Trouble splitting on line breaks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpmarkee
    New Member
    • Nov 2008
    • 2

    Trouble splitting on line breaks

    I am trying to split a text file based on line breaks. The following code seems to be splitting on every 'r' or 'n' in the file not on line breaks. Could someone tell me what I am doing wrong,

    Dim AllData = filestream.Read ToEnd()
    Dim Rows = AllData.Split(" \r\n".ToCharArr ay())


    Thanks!
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Originally posted by jpmarkee
    I am trying to split a text file based on line breaks. The following code seems to be splitting on every 'r' or 'n' in the file not on line breaks. Could someone tell me what I am doing wrong,
    Dim AllData = filestream.Read ToEnd()
    Dim Rows = AllData.Split(" \r\n".ToCharArr ay())
    Thanks!
    try using 2 backslashes
    Code:
    Dim Rows = AllData.Split("\\r\\n".ToCharArray())
    Nathan

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      VB doesn't support the character escaping, you will have to use the vbCRLF object (not sure where you get that, some VB person would know)

      You could also probably get away creating a char array and filling it with the ascii integer values that corrospond to the \r and \n characters

      Comment

      • jpmarkee
        New Member
        • Nov 2008
        • 2

        #4
        Ended up having to use:

        Dim Rows = AllData.Split(E nvironment.NewL ine.ToCharArray ())

        Comment

        Working...