Results 1 to 2 of 2

Thread: [2005] Splitting a file

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    [2005] Splitting a file

    Hi

    I have a text file that contains groups of data like this

    group 1
    one
    two
    three

    group 2
    four
    fiev
    six

    group 3
    etc
    ...


    I have the entire text file loaded into a string and I want to extract the 'groups' of data into serperate string variables.

    How can I use the Split statement to do this?

    I thought I would have been able to use

    VB Code:
    1. dim groups() as string = text.Split(vbcrlf & vbcrlf)
    but that only splits it line by line

    If I have to I will just do it manually but I was hoping I could do this with Split

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Splitting a file

    You could use the Regex.Split method. That let's you specify a pattern as the delimiter rather than a specific character or string. You just need to determine the appropriate pattern that matches your group headers. That will get each group as an element of a string array and you can use String.Split to split each group on line breaks.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width