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
  • 43
  • 8

4 Answers4

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

EditText1.setText(str1);
EditText2.setText(str2);
Kuldeep Kulkarni
  • 786
  • 5
  • 19
2

You can use

String[] strArr = yourString.split("\\,");
et_tnum.setText(strArr[0]);
et_pass.setText(strArr[1]);
AwaisMajeed
  • 1,936
  • 2
  • 9
  • 23
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"

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

This answer is from this post

Community
  • 1
  • 1
Zaki Pathan
  • 1,692
  • 1
  • 11
  • 26
1

Try

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

accountNumber = data[0];
password = data[1];
PEHLAJ
  • 9,590
  • 9
  • 39
  • 51