Sidebar

Strip alpha characters from the value in OBX-5 so only the numeric values remain

0 votes
389 views
asked Dec 9, 2016 by russell-c-4612 (140 points)
I have a result like OBX-5 = "1.25 fasting", I want to return to a variable just the 1.25

Everything I've tried so far, including regex is not working. Any suggestions?

1 Answer

0 votes

The StringUtils.replace() method only replaces string literals and does not accept regular expressions.  The easiest way to do this it to convert the source value to a java string and use the String.replaceAll() method.

Here is an example:

var before = "1.25 fasting";
var after = (new java.lang.String(before)).replaceAll('[A-z ]', '');
qie.debug(before);
qie.debug(after);
 

This will take the before string and replace any character between upper case A and lowercase z and any spaces with an empty string (basically removing the value).

answered Dec 9, 2016 by ben-s-7515 (12,640 points)
...