2

I have a incoming string looking like this: xxxx::xxxxx::xxxxxx

How can I split the string after every '::'? I can get it to do with just one colon, but not two.

Rnft
  • 105
  • 1
  • 1
  • 12
  • possible duplicate of [string.split - by multiple character delimiter](http://stackoverflow.com/questions/1254577/string-split-by-multiple-character-delimiter) – Anirudha Nov 27 '13 at 11:06

2 Answers2

6

Try this:

var splitted = 
         yourString.Split(new []{"::"},StringSplitOptions.RemoveEmptyEntries);

You can split only on string[] not on string

EDIT:

as Adil said you can always use Regex.Split

var splitted = Regex.Split(yourString, "::");
Kamil Budziewski
  • 21,991
  • 13
  • 83
  • 101
  • 2
    Could be splitted without string array using Regex.Split var arr = Regex.Split(string, "::"); – Adil Nov 27 '13 at 11:15
0

Or you could use this code snippet :

        List<string> resList = new List<string>();
        int fIndx = 0;
        for (int i = 0; i < a.Length; i++)
        {
            if(a[i] == ':' && a[i+1] == ':') 
            {
                resList.Add(a.Substring(fIndx, i - fIndx));
                fIndx = i + 2;
            }
        }
Vahid Nateghi
  • 566
  • 5
  • 13