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.
Asked
Active
Viewed 1,367 times
4 Answers
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
-
Perfect answer Sir. if i want receive again,still that previous String is there. can i overwrite them? – M.m. Samy Apr 05 '17 at 10:46
-
Happy to help you :) :). Sorry I can't understand what you trying to say in comment – Zaki Pathan Apr 05 '17 at 10:51
-
-
i mean, I've Successfully Received those Strings into Corresponding EditText. by second time if i receive Strings like that, new strings will be added with old strings, it cant be overwrites.. when i receive second time Old Strings should be Replaced by New Strings .. – M.m. Samy Apr 05 '17 at 10:55
-
1In edittext if you do settext then it is automatically overwrite please check. you need to overwrite string? – Zaki Pathan Apr 05 '17 at 10:57
-
-
-
i have a doubt in php with mysql database. i cannot ask questions anymore, can u please help me ? – M.m. Samy May 03 '17 at 06:30
1
Try
String[] data = str.split(",");
accountNumber = data[0];
password = data[1];

PEHLAJ
- 9,980
- 9
- 41
- 53