由于项目需要自己写了一个字符串分割实现代码以下:
#region 分割字符串
/// <param name="strContent">分割前字符串</param>
/// <param name="strSplit">分割字符</param>
/// <returns>返回分割后的数组</returns>
public static string[] SplitString(string strContent, string strSplit)
{
if (!string.IsNullOrEmpty(strContent))
{
if (strContent.IndexOf(strSplit) < 0)
return new string[] { strContent };
return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase);
}
else
return new string[0] { };
}
/// <summary>
/// 分割字符串
/// </summary>
/// <returns></returns>
public static string[] SplitString(string strContent, string strSplit, int count)
{
string[] result = new string[count];
string[] splited = SplitString(strContent, strSplit);
for (int i = 0; i < count; i++)
{
if (i < splited.Length)
result[i] = splited[i];
else
result[i] = string.Empty;
}
return result;
}
#endregion