private string[] GetChar(string target)
{
string[] flag = new string[target.Length];
for (int nI = 0; nI < target.Length; nI++)
{
flag[nI] = target.Substring(nI, 1);
}
return flag;
}
{
string[] flag = new string[target.Length];
for (int nI = 0; nI < target.Length; nI++)
{
flag[nI] = target.Substring(nI, 1);
}
return flag;
}
foreach (char c in chars)
Debug.WriteLine(c);
s[1] -> 'b'
s[2] -> 'c'字符串本身是字符数组...
string str = "123456789";
for (int i = 0; i < str.Length; i++)
{
Response.Write(str.Substring(i,1)+"<br />"); }
直接STRING的函数
char [] charArray = strTest.ToCharArray();
foreach (char ch in charArray)
{
Console.WriteLine(ch);
}
static void Main(string[] args)
{
string a = "abcdefg";
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine("a[{0}]={1}" ,i,a[i]);
}
Console.ReadLine();
}
1、用string..ToCharArray();
2、字符串本身就可以使用下标来访问每个字符,因为字符串定义了索引
string s = "abcdefg";
char c;
foreach c in s
{
Console.WriteLine(c);
}