在 c#.net 中按 2 对反转字符串 [英] Reverse string by 2 pair in c#.net
本文介绍了在 c#.net 中按 2 对反转字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以 2 对反转意味着例如:我们有一个字符串helloworld",我们需要以返回ehllworodl"的方式输出.我们可以看到每一对都反转并连接起来输出.
Reversing in 2 pairs means for example: we have a string "helloworld" we need to output in a way that it returns "ehllworodl". We can see that each pair it reverse and concatenated for output.
推荐答案
试试这个
string input = "helloworld";
string output = "";
for (int i = 0; i < input.Length - 1; i += 2)
{
output += input[i + 1];
output += input[i];
}
这篇关于在 c#.net 中按 2 对反转字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文