字符串顺序(倒序)
把qwertyui 转换成iuytrewq --------------------编程问答-------------------- string s = “qwertyui”char[] cs = s.ToCharArray();
Array.Reverse(cs);
s = new string(cs);
--------------------编程问答-------------------- 把字符串转换成ascii --------------------编程问答--------------------
// 反转字符串--------------------编程问答--------------------
string Reverse(string s)
{
StringBuilder sbReversed = new StringBuilder();
for (int i = s.Length - 1; i >= 0; i--)
sbReversed.Append(s[i]);
return sbReversed.ToString();
}
string Reverse(string s)
{
if (s.Length == 1)
return s;
else
return Reverse(s.Substring(1, s.Length - 1), -s.Length) + s[0].ToString();
} --------------------编程问答-------------------- 用循环:
string str = "qwertyui";
char[] list = str.ToCharArray();
for (int i = str.Length - 1; i >= 0; i--)
{
textBox1.Text += list[i];
} --------------------编程问答-------------------- 方法太多^_^ --------------------编程问答-------------------- 晕,发错。
string Reverse(string s)
{
if (s.Length == 1)
return s;
else
return Reverse(s.Substring(1, s.Length - 1)) + s[0].ToString();
} --------------------编程问答-------------------- 关键是string是不可变的。
一般借用StringBuilder来做倒序 --------------------编程问答-------------------- 转成字符数组。倒序。 --------------------编程问答-------------------- private string Reverse(string s)
{
char[] cs = s.ToCharArray();
char cTmp ;
int strLength = s.Length;
int times = i< strLength /2;
for(int i = 0; i< times ; i++)
{
cTmp = cs[i];
cs[i] = cs[strLength - 1];
cs[strLength - 1] = cTmp;
}
return cs.ToString();
}
补充:.NET技术 , C#