我是编程的初学者,我已经在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;
答案 0 :(得分:1)
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());
答案 1 :(得分:1)
// get text from EditText
String a = editText1.getText().toString();
// convert it to number
String temp = "LMNAOTUTRYEN";
String ans = "";
for (int i = 0; i < a.length(); i++) {
ans += temp.indexOf(a.charAt(i));
}
// show the number
textView1.setText(ans);
答案 2 :(得分:1)
您没有指定要获取ASCII值或数值。我是根据ASCII值完成的。这是代码。
String temp = "LMNAOTUTRYEN";
StringBuilder ans = new StringBuilder();
for(int i = 0; i < temp.length(); i++) {
int j = temp.charAt(i);
ans.append(String.valueOf(j));
}
输出为767778657984858482896978。