How to recover integers?

  • A+

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:" +;             System.out.println("Id is:" +;             System.out.println("Value is:" +;         } 

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.


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