首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2013-08-01 
c# 字符串取反请教c#字符串取反string a1 A1B2C3D4想达到取反的结果是:D4C3B2A1请教写个详细代码,达

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;


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

 

热点排行