javastringfindbufferedstream

How to find a specific value after a specific word in Java?


I got a text from a BufferedReader and I need to get a specific value in a specific string.

This is the text:

    aimtolerance = 1024;
    model = Araarrow;
    name = Bow and Arrows;
    range = 450;
    reloadtime = 3;
    soundhitclass = arrow;
    type = Ballistic;
    waterexplosionclass = small water explosion;
    weaponvelocity = 750;

        default = 213;
        fort = 0.25;
        factory = 0.25;
        stalwart = 0.25;
        mechanical = 0.5;
        naval = 0.5;

I need to get the exact number between default = and ;

Which is "213"


Solution

  • Something like this....

    String line;
    while ((line = reader.readLine())!=null) {
       int ind = line.indexOf("default =");
       if (ind >= 0) {
          String yourValue = line.substring(ind+"default =".length(), line.length()-1).trim(); // -1 to remove de ";"
          ............
       }
    }