Sidebar

How can I split dose and dose unit in code?

0 votes
200 views
asked Apr 6, 2017 by brandon-w-8204 (33,270 points)
I have one of the following strings:
4ml
0.5ml
6mg

How can I split the dose and the dose Unit so it can be placed in separate fields.

1 Answer

0 votes

Here is a sample code to split them up:

var pattern = java.util.regex.Pattern.compile("^([\\d,.]+)([A-z]+)");
            var matcher = pattern.matcher(combinedDose);
            var dose;
            var doseUnits;
            if (matcher.find()) {
               dose = matcher.group(1);
               doseUnits = matcher.group(2);
            }
 

answered Apr 6, 2017 by brandon-w-8204 (33,270 points)
...