将以逗号分隔的字符串转换成字符串数组

#region public static string[] StrList(string ValStr)
///
/// 将以逗号分隔的字符串转换成字符串数组
///

/// 原字符串
/// string[]
public static string[] StrList(string ValStr)
{
    int i = 0;
    string TempStr = ValStr;
    string[] returnStr = new string[ValStr.Length + 1 - TempStr.Replace(",", "").Length];
    ValStr = ValStr + ",";
    while (ValStr.IndexOf(',') > 0)
    {
        returnStr[i] = ValStr.Substring(0, ValStr.IndexOf(','));
        ValStr = ValStr.Substring(ValStr.IndexOf(',') + 1, ValStr.Length - ValStr.IndexOf(',') - 1);
        i++;
    }
    return returnStr;
}
#endregion

你可能感兴趣的:(将以逗号分隔的字符串转换成字符串数组)