How Can I split sentence like :
aaaa "00000036" dddd "Raison aaaMotif" a été enregistrée avec succès.
to get 00000036 number !!!?
MsgOffreAdded =.Span_MSG_Id_Offre_added.getText();
/*
* split to get code
*/
String[] arr = MsgOffreAdded.split("\\"|\\""");
System.out.println("code new offre de prix" + arr[1]);
MsgOffreAdded = arr[1];
What you can do is :
String str = "aaaa \"00000036\" dddd \"Raison aaaMotif\" a été enregistrée avec succès.";
String []splitStr = str.split("\"");
System.out.println(splitStr[0]); //print -> aaaa
System.out.println(splitStr[1]); //print -> 00000036
As you can see, In the above snippet I've use \\"someString"\\
in my code to have multiple double quotes in my String
!
Happy coding!
如果您只对数字感兴趣,也可以执行str.replaceAll("^.*\\"([0-9]+)\\".*$", "$1")
。
String stringToSplit = "aaaa 00000036 dddd Raison aaaMotif a été enregistrée avec succès.";
String numberString = stringToSplit.replaceAll("[^0-9]", "");
int number = Integer.valueOf(numberString);
Toast.makeText(this,number,Toast.LENGTH_SHORT).show();
that toast will show 00000036 .. have fun
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.