Best approach of Parsing variable data from a string?

I am building a project that refers to GCode for its data input.
I have managed to put together a sketch that reads the file one line at a time, and currently ignores anything that doesnt have a G in front of it!
Here is a snippet of the file (each line is a string)

G03 X128.058354 Y39.348978 Z-0.125000 I-1.307156 J-7.287508
G03 X127.286493 Y39.381414 Z-0.125000 I-0.772541 J-9.183613
G01 X126.899108 Y39.381414 Z-0.125000
G01 X126.899108 Y41.491541 Z-0.125000
G01 X135.489923 Y41.491541 Z-0.125000
G01 X135.489923 Y8.833634 Z-0.125000
G00 Z1.000000

So i want to populate three Floats with the appropriate values, X, Y and Z (I, and J are getting ignored for now)

As you can see, X is not necessarily the first number a parse would come across!
is there a way I can scan through the string to the X, if there is an X fill it with the float (and if not do something else with it perhaps), and then scan across to the Y, and then the Z?
I have found "IndexOf", but have not managed to work out how to grab the number which follows that position.
I suspect it might be a bit like this?:

   int indexX = inputString.indexOf('X');
        if (indexX > 1) int x = inputString[indexX].parseFloat();

except it isnt., or at least i get:

HelloWorld:81: error: request for member 'parseFloat' in 'inputString.String::operator[](((unsigned int)indexX))', which is of non-class type 'char'

any pointers as to which function would achieve what i need?

Thanks

There are Gcode parsers than run on Ardiunos already I believe - it might be easier
to borrow from these rather than reinvent the wheel (well, the parser). Best approach
depends on what you mean by "best", BTW!

You can use the String functions (note the capital S) to do parsing. If the floats are basically character string representations of a number, then you can probably use the StringIndexOf function to locate the x, then use the StringReplace function to replace the x with the float string.

You could use strtok() to split the string into words where there are spaces, verify (and discard) the next character which you expect to be 'X'/'Y'/'Z' and then use atof() to convert the remaining numeric string into a float. However, using an existing GCODE parser does feel like an easier and more reliable approach.