读书人

c# 字符串取反,该如何处理

发布时间: 2013-08-01 15:23:18 作者: rapoo

c# 字符串取反
请教c#字符串取反

string a1 = "A1B2C3D4";
想达到取反的结果是:D4C3B2A1

请教写个详细代码,达到以上要求。谢谢 C#
[解决办法]

 static void Main(string[] args)
{
string a1 = "A1B2C3D4";
string[] temp = new string[a1.Length / 2];
for (int i = 0, j = 0; i < a1.Length && j <= a1.Length; i = i + 2, j++)
{
temp[j] = a1[i] + "" + a1[i + 1];
}

string result = string.Empty;
for (int i = temp.Length - 1; i >= 0; i--)
{
result += temp[i];
}

Console.WriteLine(result);
}

[解决办法]
string str = "A1B2C3D4";
int len = str.Length;
int x = len;
string str2 = "";
for (int i = 0; i < len / 2; i++)


{
x = x - 2;
str2 = str2 + str.Substring(x,2);
}
this.da.Text = str2;


[解决办法]
楼主,解决了吗?

 

读书人网 >C#

热点推荐