如何在Java中的特定单词之后找到具体的值? [英] How to find a specific value after a specific word in Java?
本文介绍了如何在Java中的特定单词之后找到具体的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 BufferedReader
中获得了一个文本,我需要在特定的字符串中获得一个特定的值。
这是文字:
aimtolerance = 1024;
model = Araarrow;
name =弓箭;
范围= 450;
reloadtime = 3;
soundhitclass = arrow;
type =弹道;
waterexplosionclass =小水爆;
weaponvelocity = 750;
default = 213;
fort = 0.25;
factory = 0.25;
stalwart = 0.25;
mechanical = 0.5;
naval = 0.5;
我需要获得
default = 和;
这是213
解决方案
字符串行; ((line = reader.readLine())!= null){
int ind = line.indexOf(default =);
if(ind> = 0){
String yourValue = line.substring(ind +default =。length(),line.length() - 1).trim(); // -1删除;
............
}
}
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"
解决方案
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 ";"
............
}
}
这篇关于如何在Java中的特定单词之后找到具体的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文