Searching string in between characters?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul73
    New Member
    • Sep 2007
    • 13

    Searching string in between characters?

    Hi everyone,

    I've had good luck with the questions I've posted on here so I'm going to try again.

    Let's say you had a string that looked like this:

    Some text | Some text | Text to extract | Some text
    How would you extract everything between the 2nd and 3rd |? I know how to find the first or last occurance of a character but I'm not sure how to do this.

    Thanks for your help,
    Paul
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    How does this look?

    [CODE=cpp] string str = "Some text | Some text | Text to extract | Some text";
    string[] splits = str.Split('|');
    foreach (string s in splits)
    {
    Console.WriteLi ne(s);
    }[/CODE]

    Comment

    • Paul73
      New Member
      • Sep 2007
      • 13

      #3
      Hi Shashi,

      That's just what I was looking for. Thank you. This is something I'm sure to use many times.

      Paul

      Comment

      Working...