"Current Peak : 830 300"
How can I get hold of the two numbers, but without the spaces. (There are 5 or more spaces in between each substring)
Using apache's StringUtils I got so far:
String workUnit =
StringUtils.substringAfter(thaString,
":");
This gives bac开发者_开发问答k:
"830 300"
but still with a lot of spaces and not separated.
Or just using core java:
String input = "Current Peak : 830 300";
String[] parts = input.split("\\s+"); // Split on any number of whitespace
String num1 = parts[3]; // "830"
String num2 = parts[4]; // "300"
Untested, but this should give you your two numbers:
String[] workUnits = StringUtils.split(StringUtils.substringAfter(thaString, ":"));
You can do something like this:
Pattern patt = Pattern.compile("Current Peak :\\s*(\\d*)\\s*(\\d*)");
Matcher matcher = patt.matcher("Current Peak : 830 300");
if (matcher.find()) {
String first = matcher.group(1); // 830
String second = matcher.group(2); // 300
// ...
}
String[] workUnits = StringUtils.substringAfter(thaString,":").split("\\s+");
精彩评论