sheraz amin
sheraz amin

Reputation: 1149

Conversion of Alphabets into numbers

I am beginner in programming , I have converted numbers into alphabets in C# Now i want to convert that Alphabets back to those numbers in Android .Thanks in advance.Code which i used for 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;

Upvotes: 0

Views: 588

Answers (3)

Debarati
Debarati

Reputation: 3286

You didn't specify that you want to get ASCII value or numeric value. I have done it according ASCII value.Here is the code.

 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));
    }

The output is 767778657984858482896978.

Upvotes: 1

wannik
wannik

Reputation: 12696

// 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);

Upvotes: 1

nostra13
nostra13

Reputation: 12407

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);

But use StringBuilder better:

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());

Upvotes: 1

Related Questions