I’m working on assignment here, part of which requires me to parse integers from a string that has groups of digits separated by any other character. I know I can use the wrapper class method Integer.parseInt(string) to parse ints from a string containing just digits, but how would I go about doing it in this case? So far, I’ve considered doing a linear search of the string and assigning a variable to the first index where a digit appears and the index after the last digit appears and creating a temporary substring based on these indices from which to parse the int. Is this a valid approach? Perhaps there is a more efficient one?
Share
If it can be any character (one or more), then this might be helpful:
E.g.:
Output: