| Below code will split string with more then one character input:-
public string[] SplitText(string textToSplit,string splitter)
{
if (textToSplit.IndexOf(splitter) != -1 && splitter != string.Empty)
{
int count = 0;
string temp = textToSplit;
int count2 = splitter.Length;
while (temp.IndexOf(splitter) != -1)
{
int seq = temp.IndexOf(splitter);
int top = seq + count2;
temp = temp.Remove(0, top);
count++;
}
string[] splittedText = new string[count + 1];
int i = 0;
while (textToSplit.IndexOf(splitter) != -1)
{
int seq = textToSplit.IndexOf(splitter);
splittedText[i] = textToSplit.Substring(0, seq);
textToSplit = textToSplit.Remove(0, (seq + count2));
i++;
}
splittedText[count] = textToSplit;
return splittedText;
}
return new string[] {textToSplit};
} | | |