C# 扩展 string Split 方法
// 使用扩展方法做
public static string[] SplitExt(this string sourceString, string splitString)
{
List<string> arrayList = new List<string>();
string s = string.Empty;
while (sourceString.IndexOf(splitString) > -1)
{
s = sourceString.Substring(0, sourceString.IndexOf(splitString));
sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);
arrayList.Add(s);
}
arrayList.Add(sourceString);
return arrayList.ToArray();
}
// 使用普通方法做
public static string[] StringSplitExt(string sourceString, string splitString)
{
List<string> arrayList = new List<string>();
string s = string.Empty;
while (sourceString.IndexOf(splitString) > -1)
{
s = sourceString.Substring(0, sourceString.IndexOf(splitString));
sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);
arrayList.Add(s);
}
arrayList.Add(sourceString);
return arrayList.ToArray();
}
public static string[] SplitExt(this string sourceString, string splitString)
{
List<string> arrayList = new List<string>();
string s = string.Empty;
while (sourceString.IndexOf(splitString) > -1)
{
s = sourceString.Substring(0, sourceString.IndexOf(splitString));
sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);
arrayList.Add(s);
}
arrayList.Add(sourceString);
return arrayList.ToArray();
}
// 使用普通方法做
public static string[] StringSplitExt(string sourceString, string splitString)
{
List<string> arrayList = new List<string>();
string s = string.Empty;
while (sourceString.IndexOf(splitString) > -1)
{
s = sourceString.Substring(0, sourceString.IndexOf(splitString));
sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);
arrayList.Add(s);
}
arrayList.Add(sourceString);
return arrayList.ToArray();
}