Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check string with delimiter expected

I want to split string got from bluetooth. i'm using

StringTokenizer  splitStr = new StringTokenizer(readMessage, "\\|");
String numberSpeed = splitStr.nextToken();  //splitStr[0].replaceAll("\\D+","");
String numberTorque = splitStr.nextToken();  //splitStr[1].replaceAll("\\D+","");
numberSpeed = numberSpeed.replaceAll("\\D+","");
numberTorque = numberTorque.replaceAll("\\D+","");

Did it with split string before. If i get corupted data without delimiter the app crashes while trying to do impossible.

  • How to check if there is delimiter or not and then proceed split or skip it?
like image 551
Martynas Avatar asked May 08 '26 13:05

Martynas


1 Answers

you can check for delimeter in string by contains() method

if(str.contains("_your_delimiter")) {   //for safe side convert your delimeter and search string to lower case using method toLowerCase()
     //do your work here
}
like image 125
Waqar Ahmed Avatar answered May 10 '26 04:05

Waqar Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!