跳至主要内容

C#中遍历字符串中的每个字符的

string testStr = "abc123";
foreach (char c in testStr)
{
  Console.WriteLine(c.ToString());
}
或者
string testStr = "abc123";
for (int counter = 0; counter < testStr.Length; counter++)
{
   Console.WriteLine(testStr[counter]);
}

评论

此博客中的热门博文