Reputation: 41
I have Two EditText(id=et_tnum,et_pass). I Received a String like 12345,mari@123 inside EditText1(et_tnum) . I want to Split them by Comma and After Comma i should Receive Remainder string into EditText2(et_pass). Here 12345,mari@123 is Account Number & Password Respectively.
Upvotes: 1
Views: 1672
Reputation: 1782
String CurrentString = "12345,mari@123";
String[] separated = CurrentString.split(",");
//If this Doesn't work please try as below
//String[] separated = CurrentString.split("\\,");
separated[0]; // this will contain "12345"
separated[1]; // this will contain "mari@123"
Also look at this post:
There are other ways to do it. For instance, you can use the StringTokenizer class (from java.util):
StringTokenizer tokens = new StringTokenizer(CurrentString, ","); String first = tokens.nextToken();// this will contain "12345" String second = tokens.nextToken();// this will contain "mari@123" // in the case above I assumed the string has always that syntax (foo: bar) // but you may want to check if there are tokens or not using the hasMoreTokens method
Upvotes: 2
Reputation: 10126
Try
String[] data = str.split(",");
accountNumber = data[0];
password = data[1];
Upvotes: 1
Reputation: 2314
You can use
String[] strArr = yourString.split("\\,");
et_tnum.setText(strArr[0]);
et_pass.setText(strArr[1]);
Upvotes: 2
Reputation: 796
String[] strSplit = YourString.split(",");
String str1 = strSplit[0];
String str2 = strSplit[1];
EditText1.setText(str1);
EditText2.setText(str2);
Upvotes: 3