How to recover integers?

  • A+
Category:Languages

I get a string and I have to retrieve the values

Je pense que nous devons utiliser le ".slit"

if (stringReceived.contains("ID")&& stringReceived.contains("Value")) { 

here is my character string: [11/2/19 9:48:25] Timestamp=1549878505 ID=4 Value=2475

I would like to recover the value of Timestamp, Id and Value..

 


You can also use regex for that. Something like:

 String example="[11/2/19 9:48:25] Timestamp=1549878505 ID=4 Value=2475";                   Pattern pattern=Pattern.compile(".*Timestamp=(//d+).*ID=(//d+).*Value=(//d+)");         Matcher matcher = pattern.matcher(example);         while(matcher.find()) {             System.out.println("Timestamp is:" + matcher.group(1));             System.out.println("Id is:" + matcher.group(2));             System.out.println("Value is:" + matcher.group(3));         } 

If the order of tokens can be different (for example ID can come before Timestamp) you can also do it. But since it looks like log which is probably structured I doubt you will need to.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: