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"
you can use Properties class to load the string and find any value from it
Split the string on "default =" and then use indexOf to find the first occurrence of ";". Do a substring from 0 to the index and you have your value.
See http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
Using regular expressions:
Something like this....
If just care about the end result, i.e. getting stuff out of your '=' separated values text file, you might find the built in Properties object helpful?
http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html
This does much of what you need. Of course if you're specifically wanting to do this manually, it's maybe not the right option.