0

How do i parse a substring in java

I had run a class that gives me an output which looks like this: Process ID... Thread list... TID Start address Thread state ------------- 5372 0 Wait 5512 140729994628784 Wait 5624 0 Wait 5511 140729994628784 Wait 5510 140729994628784 Wait 55009 140729994628784 Wait 5624 0 Wait ....the list is long.... i need to parse a substring of above output which is like eg. tid = 5511 (knowing the status is 1) to be used to another class that takes the tid (eg.5511) from the above output how do i do? tried but didn't work so far

20th May 2020, 11:41 AM
Emanuela Telescu
Emanuela Telescu - avatar
5 Antworten
0
Am may not understood exactly, but Trying to save in a string and split it, then string[0] will give that 5511.. Is this not work?
20th May 2020, 12:25 PM
Jayakrishna 🇮🇳
0
how to save in a string and split is can you help? I'm really a beginner
20th May 2020, 12:59 PM
Emanuela Telescu
Emanuela Telescu - avatar
0
for example if you consider first line as string, then String str="5372 0 wait" ; String s[] =str. split(" ") ; System.out.println(s[0]); will output 5372. But for the above, problem it depends your code, how you producing output.....!
20th May 2020, 1:09 PM
Jayakrishna 🇮🇳
0
what about string.length() and indexOf()?
20th May 2020, 1:28 PM
Emanuela Telescu
Emanuela Telescu - avatar
0
String.length () returns the string length, str.indexOf("5372") returns first occurrence of that string in str. Otherwise returns -1. How you want to use these..? If tid is a string, then str="5372 0 wait" ; str.substring(str.indexOf(tid), str.indexOf(tid)+tid.length()+1) ; Returns 5372
20th May 2020, 1:39 PM
Jayakrishna 🇮🇳