gpt4 book ai didi

c# - c#中字符串的反转部分

转载 作者:太空宇宙 更新时间:2023-11-03 19:48:32 25 4
gpt4 key购买 nike

<分区>

如何反转用户输入字符串的一部分?只是数字不应该反转所有其他部分必须反转。

ABC123DEF   --> CBA123FED
DISK0123CAR --> KSID0123RAC
596ABCDEF --> 596FEDCBA

提前谢谢你这是我的代码:

public static string ReverseStr(string sStrRev)
{
string output = "";
Dictionary<int, char> SChar = new Dictionary<int, char>();

int Cposition = 0;

for (int i = sStrRev.Length - 1; i >= 0; i--)
{
if (sStrRev[i] != '1' && sStrRev[i] != '2' && sStrRev[i] != '3'
&& sStrRev[i] != '4' && sStrRev[i] != '5'
&& sStrRev[i] != '6' && sStrRev[i] != '7'
&& sStrRev[i] != '8' && sStrRev[i] != '9'
&& sStrRev[i] != '0')
output += sStrRev[i];
else
{
SChar.Add(Cposition, sStrRev[i]);
}
Cposition++;
}

for (int i = 0;i<sStrRev.Length ; i++)
{
if (SChar.ContainsKey(i))
output.Insert(i, SChar[i].ToString());
}
return output;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com