gpt4 book ai didi

java - 将字母转换为数字

转载 作者:行者123 更新时间:2023-12-02 00:34:30 27 4
gpt4 key购买 nike

我是编程初学者,我已经在 C# 中将数字转换为字母,现在我想将字母转换回 Android 中的数字。提前致谢。我用于 C# 的代码:

string a = textBox1.Text;
string temp = "LMNAOTUTRYEN";
string ans = "";
for (int i = 0; i < a.Length; i++)
ans += temp[a[i] - 48];
textBox2.Text = ans;

最佳答案

String a = textBox1.getText().toString();
String temp = "LMNAOTUTRYEN";
String ans = "";
for (int i = 0; i < a.length(); i++)
ans += temp.charAt(a.charAt(i) - 48);
textBox2.setText(ans);

但是使用 StringBuilder 更好:

String a = textBox1.getText().toString();
String temp = "LMNAOTUTRYEN";
StringBuilder ans = new StringBuilder();
for (int i = 0; i < a.length(); i++)
ans.append(temp.charAt(a.charAt(i) - 48));
textBox2.setText(ans.toString());

关于java - 将字母转换为数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8178606/

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