Thursday, 29 September 2011

Split a string in array by a string delimiter in C#


private static string[] SplitString(string valueString, string delimiter)
{
        string[] RetVal;
        int Index = 0;
        string Value;
        List<string> SplittedList = new List<string>();

        while (true)
        {
            Index = valueString.IndexOf(delimiter);
            if (Index == -1)
            {
                if (!string.IsNullOrEmpty(valueString))
                {
                    SplittedList.Add(valueString);
                }
                break;
            }
            else
            {
                Value = valueString.Substring(0, Index);
                valueString = valueString.Substring(Index + delimiter.Length);
                SplittedList.Add(Value);
               
            }

        }

        RetVal = SplittedList.ToArray();

        return RetVal;
}

No comments:

Post a Comment