Extract text from text string
On 2/9/2021 8:44 AM, john taiariol wrote:
Hello,
I would like to extract the X-coordinate from a string of NC programming code for a CNC machine. A typical line of code might look like this:
(M72)
G0G54X202.819Z54.5
#590=2(RECOVER_FACE TURN)
G1X167.751F#101M26
G0Z61.398
X163.682
G1 X 153.873 Z 62
X147.873
G0X162.375Z62.394
My preference would be a formula. I would like the adjacent cell to contain only the value for "X" ie. in the first line "G0G54X202.819Z54.5", the X-coord is 202.819. Please note sometimes the text may have a space after the X or after the coordinate. It is not consistent. I have tried "find" and "mid" with limited success. I was wondering if it's possible to analyze each character in the string after the "X" and verify if it's a number or a period. Thank you in advance for any help.
With the presumption of always being F7.3 format, the following seems to
work
=VALUE(MID(SUBSTITUTE(A7," ",""),FIND("X",SUBSTITUTE(A7," ",""))+1,7))
It's more work for variable-width fields, unfortunately, because then
the last "7" for number of characters is also a variable.
Unfortunately, the Excel VALUE() function isn't smart-enough to just
convert from the starting point until it runs out of digits as will C
|fscanf|
G0G54X202.819Z54.5 202.819
#590=2(RECOVER_FACE TURN) #VALUE!
G1X167.751F#101M26 167.751
G0Z61.398 #VALUE!
X163.682 163.682
G1 X 153.873 Z 62 153.873
X147.873 147.873
G0X162.375Z62.394 162.375
is result of above...
--
|