String has a method called split().
String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
In the example above, you can use it this way.
If you make an exception,
if (string.contains("-")) {
String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
} } else {
throw new IllegalArgumentException("String " + string + " does not contain -");
}
You can do it.
© 2024 OneMinuteCode. All rights reserved.