The above is a part of my log file.
The problem i faced is how to just get ID with its particular RSSI value ?
Because i want to calculate the average RSSI value for each different ID .
I tried split.string, delimiter, regular expression but i became blur after this. I don know what is the best way to do this !
Im new in Java, so kindly help me.... Thank .!

8 Years
Discussion Span
Last Post by BestJewSinceJC

Both the String class's split method and regular expressions would be good solutions for this problem. Using the split method and splitting on "[|]" would probably be easier though. The reason you would have to split on [|] and not on | is as follows: (quoted from s.o.s's post in another thread):

| has a special meaning when it comes to regular expressions, it's called the alternation symbol.

If you have something like "##|##|##".split("|") , it's the same as "##|##|##".split("") since a single pipe symbol is the same as saying "alternate between a blank string and another blank string" which is the same as a blank string.

You can either:

  • Escape this pipe character and tell the regex engine to treat is at a literal pipe character. Something like "string".split("\\|")
  • Use character classes, similar to the example posted above (i.e. [|] )

Anyway, I'm assuming that before you did that, you would read each line of text into a separate String using Scanner's nextLine() method, so that split([|]) would give you an array of 7 elements per line. Then you could simply tell it to give you array[2] (your ID number) and array[4] (the corresponding RSSI)

Edited by BestJewSinceJC: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.