java - How to make a subString from another string by searching for certain characters -
string x = "id:12 patient name:..."; string z = = x.substring(3, x.indexof(' p')); i want id number
you're there. use this:-
string z = x.substring(x.indexof("id:")+3, x.indexof("patient")-1); +3 - because don't need id:
-1 - because don't need space before patient
this taking account there single space before patient, if not, @buhakesindi suggested use trim() method this:-
string z = x.substring(x.indexof("id:")+3, x.indexof("patient")); z = z.trim();