k41d3n
asked on
Regexp?
I have a file I am reading and I need to read a value, the block of text I am reading is this:
WebRefresh=1 (0 to 10 Minute(s))
AlarmResetMode=0 (0 to 1)
BatteryChemistry=0 (0 to 1)
StringSetup=1 (1 to 2), 40 (1 to 400), 1, 17.0 ( 6.5, 7.0, 8.0, 9.0,12.0,13.5,17.0)
BatteryAHCapacity=100 (100 to 2000)
BalanceBoostTime=3 (3 to 10 Second(s))
CellVoltageLimitMinMax=2.1 50, 2.400 (2.000 to 2.500 V)
PilotTempLimitMax=95.0 F (85.0 to 120.0 F)
AmbientTempLimitMinMax=50. 0, 95.0 F (50.0 to 120.0 F)
ResponseDeviationAlarmLeve l=20 (10 to 20 %)
DischargeDeviationAlarmLev el=15 (5 to 20 %)
RippleCurrentAlarmLevel=5 (0 to 2000)
now, what I do now, is look for the parameter then split it on the = sign and I need to return everything after the = sign up to the ( how would I go about this?
I am horrible with expressions.
This is what I have now that splits the = sign.
String setLine;
String changeValue;
while (in.available() != 0) {
// Print file line to screen
System.out.println(""+in.r eadLine()+ "\n");
setLine = in.readLine();
if (setLine.indexOf("Discharg eDeviation AlarmLevel ") != -1) {
String[] line = setLine.split("=");
changeValue = line[1].substring(1, 2);
System.out.println(changeV alue);
break;
}
}
Of course code syntax suggestions always welcome as well.
WebRefresh=1 (0 to 10 Minute(s))
AlarmResetMode=0 (0 to 1)
BatteryChemistry=0 (0 to 1)
StringSetup=1 (1 to 2), 40 (1 to 400), 1, 17.0 ( 6.5, 7.0, 8.0, 9.0,12.0,13.5,17.0)
BatteryAHCapacity=100 (100 to 2000)
BalanceBoostTime=3 (3 to 10 Second(s))
CellVoltageLimitMinMax=2.1
PilotTempLimitMax=95.0 F (85.0 to 120.0 F)
AmbientTempLimitMinMax=50.
ResponseDeviationAlarmLeve
DischargeDeviationAlarmLev
RippleCurrentAlarmLevel=5 (0 to 2000)
now, what I do now, is look for the parameter then split it on the = sign and I need to return everything after the = sign up to the ( how would I go about this?
I am horrible with expressions.
This is what I have now that splits the = sign.
String setLine;
String changeValue;
while (in.available() != 0) {
// Print file line to screen
System.out.println(""+in.r
setLine = in.readLine();
if (setLine.indexOf("Discharg
String[] line = setLine.split("=");
changeValue = line[1].substring(1, 2);
System.out.println(changeV
break;
}
}
Of course code syntax suggestions always welcome as well.
You can use this to read that file:
Properties props = new Properties();
props.load(new FileInputStream(yourFile)) ;
String value = props.getProperty("Respons eDeviation AlarmLevel "); // gets "20 (10 to 20 %)"
Properties props = new Properties();
props.load(new FileInputStream(yourFile))
String value = props.getProperty("Respons
ASKER
I ended up using:
String setLine;
String changeValue;
while (in.available() != 0) {
// Print file line to screen
System.out.println(""+in.r eadLine()+ "\n");
setLine = in.readLine();
if (setLine.indexOf("Discharg eDeviation AlarmLevel ") != -1) {
String[] line = setLine.split("=");
changeValue = line[1].substring(0, line[1].indexOf("("));
System.out.println(changeV alue);
break;
}
}
String setLine;
String changeValue;
while (in.available() != 0) {
// Print file line to screen
System.out.println(""+in.r
setLine = in.readLine();
if (setLine.indexOf("Discharg
String[] line = setLine.split("=");
changeValue = line[1].substring(0, line[1].indexOf("("));
System.out.println(changeV
break;
}
}
hi
one example to extract the e-mail addres from a string like "dfd gfdg dgdgd hje@juf.com ejfek" using RegExp
<html>
<head>
<script>
function findEmail(str) {
var regex=/[a-zA-Z][\w\.-]*[a- zA-Z0-9]@[ a-zA-Z0-9] [\w\.-]*[a -zA-Z0-9]\ .[a-zA-Z][ a-zA-Z\.]* [a-zA-Z]/;
var m=str.match(regex);
alert(m);
}
</script>
</head>
<body>
<button onclick="javascript:findEm ail('the email address Myemail@hotmail.com could be anywhere');">Find the Email</button>
</body>
</html>
or
inputs.match(/(\w+)[@](\w+ )[.](\w+)/ g,"");
u can try the same logic for ur case
one example to extract the e-mail addres from a string like "dfd gfdg dgdgd hje@juf.com ejfek" using RegExp
<html>
<head>
<script>
function findEmail(str) {
var regex=/[a-zA-Z][\w\.-]*[a-
var m=str.match(regex);
alert(m);
}
</script>
</head>
<body>
<button onclick="javascript:findEm
</body>
</html>
or
inputs.match(/(\w+)[@](\w+
u can try the same logic for ur case
try something like:
String setLine = null;
String changeValue = null;
while (null!=(setLine=in.readLin e())) {
// Print file line to screen
System.out.println(""+setL ine+ "\n");
if (setLine.indexOf("Discharg eDeviation AlarmLevel ") != -1) {
changeValue = setLine.split("=")[1].spli t(" ")[0];
// or perhaps depending on possible format of value
// changeValue = setLine.split("=")[1].spli t("\\(")[0 ];
System.out.println(changeV alue);
}
}
String setLine = null;
String changeValue = null;
while (null!=(setLine=in.readLin
// Print file line to screen
System.out.println(""+setL
if (setLine.indexOf("Discharg
changeValue = setLine.split("=")[1].spli
// or perhaps depending on possible format of value
// changeValue = setLine.split("=")[1].spli
System.out.println(changeV
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
changeValue = line[1].substring(1, 2);
is actually
changeValue = line[1];