-5

I want to get two integer values separated form a string XmodX one is before mod and other is after mod the integers can be of any length. what is the best way to to so?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Salman Arshad
  • 343
  • 6
  • 23

1 Answers1

1

This approach should work...

// The variable 'parts' will contain 2 items:  your 2 integers, though they will still be String objects
String[] parts = myString.split("mod");

try {
    int firstInt = Integer.parseInt(parts[0]);
    int secondInt = Integer.parseInt(parts[1]);
) catch(NumberFormatException nfe) {
  // One of your Strings was not an integer value
}
Drew Wills
  • 8,408
  • 4
  • 29
  • 40