例如:字符串"CSDN"
如何切割成C S D N
------最佳解决方案--------------------------------------------------------
string test = "CSDN";
string hh = string.Empty;
foreach (char s in test)
{
hh += s.ToString()+ " ";
}
Response.Write(hh);
C S D N
------其他解决方案--------------------------------------------------------
string str = "CSDN";
var ary = Regex.Split(str, @"(?<=\w)(?=\w)");
foreach (var t in ary)
Console.WriteLine(t);
------其他解决方案--------------------------------------------------------
string str="CSDN";
var ary = Regex.Split(str, @"(?<=\w)(?=\w)");
------其他解决方案--------------------------------------------------------
string[] result = "CSDN".Select(x => new string(new char[] { x })).ToArray();
------其他解决方案--------------------------------------------------------
ToCharArray ()
------其他解决方案--------------------------------------------------------
字符串本身就是字符的组合
string test = "CSDN";
foreach (char c in test)
{
richTextBox2.Text += c + "\n";
}
/*-----输出-----
C
S
D
N
*/
------其他解决方案--------------------------------------------------------
输出是怎么写的,我输出的是'CSDN'而不是我要的效果C S D N
------其他解决方案--------------------------------------------------------
谢谢了,找到想要的了
------其他解决方案--------------------------------------------------------
string str = "CSDN";
str = Regex.Replace(str, @"\S(?!$)", "$0 ");
Console.WriteLine(str);
------其他解决方案--------------------------------------------------------
还可以用insert
"abc".Insert(2, "XYZ") 的返回值为"abXYZc"。