1

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.

M.m. Samy
  • 41
  • 9

4 Answers4

3
String[] strSplit = YourString.split(",");
String str1 = strSplit[0];
String str2 = strSplit[1];

EditText1.setText(str1);
EditText2.setText(str2);
Kuldeep Kulkarni
  • 796
  • 5
  • 20
2

You can use

String[] strArr = yourString.split("\\,");
et_tnum.setText(strArr[0]);
et_pass.setText(strArr[1]);
AwaisMajeed
  • 2,254
  • 2
  • 10
  • 25
2
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
miken32
  • 42,008
  • 16
  • 111
  • 154
Zaki Pathan
  • 1,762
  • 1
  • 13
  • 26
1

Try

String[] data = str.split(",");

accountNumber = data[0];
password = data[1];
PEHLAJ
  • 9,980
  • 9
  • 41
  • 53