gpt4 book ai didi

c# - 反转 foreach 循环操作

转载 作者:行者123 更新时间:2023-11-30 20:41:40 25 4
gpt4 key购买 nike

我想将我的每个字符串字符转换/查找为 (int) 并反转此操作。我设法完成了第一部分,但第二部分给我带来了一些问题。

string input;
string encrypt = ""; string decrypt = "";

input = textBox.Text;
foreach (char c in input)
{
int x = (int)c;
string s = x.ToString();
encrypt += s;
}
MessageBox.Show(encrypt);

foreach (int i in encrypt)
{
char c = (char)i;
string s = c.ToString();
decrypt += c;
}
MessageBox.Show(decrypt);

谢谢!

最佳答案

根据我上面的建议,这是一个固定的程序

        string encrypt = ""; string decrypt = "";

string input = Console.ReadLine();
var length = input.Length;
int[] converted = new int[length];
for (int index = 0; index < length; index++)
{
int x = input[index];
string s = x.ToString();
encrypt += s;
converted[index] = x;
}

Console.WriteLine(encrypt);
for (int index = 0; index < converted.Length; index++)
{
char c = (char)converted[index];
string s = c.ToString();
decrypt += s;
}
Console.WriteLine(decrypt);

关于c# - 反转 foreach 循环操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32165221/

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