using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
可以在foreach中shi'yong字符串
foreach (char charater in myString)
{
Console.WriteLine("{0}",charater);
}
Console.ReadKey();
}
}
}
string myString = "A String";
char[] myChars = myString.ToCharArray();
//接着就可以用标准方式处理char型数组了.也
<string>.ToLower()和<string>.ToUpper()他们可以把字母转换为大写或小写
<string>.Trim()删除空格
也可以使用这些命令删除其他字符,只要在char数组中指定这些字符即可,如:
char trimChars = {' ','e','s'};
string userResponse = Console.ReadLine();
userResponse = userResponse.ToLower();
userResponse = userResponse.Trim(trimChars);//删除指定的字符
<string.TrimStart()>和<string>.TrimEnd()删除字符串前面后面的空格。