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.

dbc
  • 104,963
  • 20
  • 228
  • 340
Rnft
  • 115
  • 1
  • 2
  • 12

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
  • 22,699
  • 14
  • 85
  • 105
  • 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
  • 576
  • 5
  • 14