實現標題的功能,方法也很多。Insus.NET也為此練習一番。如有字元串: 方法一: public void SplitString(string str) { int len = str.Length; for (int i = 0; i < len; i++) { Console.WriteLi ...
實現標題的功能,方法也很多。Insus.NET也為此練習一番。
如有字元串:
string str = "Insus.NET";
public void SplitString(string str) { int len = str.Length; for (int i = 0; i < len; i++) { Console.WriteLine(str[i]); } }Source Code
public void SplitString0(string str) { string[] arr = new string[str.Length]; for (int i = 0; i < str.Length; i++) { arr[i] = str[i].ToString(); } foreach (string s in arr) { Console.WriteLine(s); } }Source Code
public void SplitString1(string str) { foreach (Char c in str.ToCharArray()) { Console.WriteLine(c); } }Source Code
public void SplitString2(string str) { string[] arr = str.Select(s => s.ToString()).ToArray(); foreach (string s in arr) { Console.WriteLine(s); } }Source Code