

autodefine "off"

'=============================================
' Add the include file into your code first. '
'=============================================
 
$include "StringMap.inc"

istring Astring[5000]
istring MyString[5000]
istring Value[5000]
int Count = 0

openconsole

'A typical string for you with all 4 values in it.
Astring = "G03 X-61.466 Y-12.517 I-1.444 J-7.482"

print
print " My string is ",Astring
print

'Lets count how many blocks of numbers there are in the string.
Count = SMCountNumBlocks(Astring)

'X has the second number block as you want to discard the "03" in "G03"
Value = ""
Value = SMGetNumBlockX(Astring,2)
print " X = ",Value

Value = ""
Value = SMGetNumBlockX(Astring,3)
print " Y = ",Value

Value = ""
Value = SMGetNumBlockX(Astring,4)
print " I = ",Value

Value = ""
Value = SMGetNumBlockX(Astring,5)
print " J = ",Value

'==================
' OR
'==================

print
Value = ""
Value = SMGetNumBlockX(Astring,2)
print " X = ","X"+Value

Value = ""
Value = SMGetNumBlockX(Astring,3)
print " Y = ","Y"+Value

Value = ""
Value = SMGetNumBlockX(Astring,4)
print " I = ","I"+Value

Value = ""
Value = SMGetNumBlockX(Astring,5)
print " J = ","J"+Value

print
print "==================================="


'A typical string for you with 2 values in it.
Astring = "G00 X-32.931 Y-29.599"

print
print " My string is ",Astring
print

'Lets count how many blocks of numbers there are in the string.
Count = 0
Count = SMCountNumBlocks(Astring)

'X has the second number block as you want to discard the "03" in "G03"

if Count >= 2
	Value = ""
	Value = SMGetNumBlockX(Astring,2)
	print " X = ",Value
endif

if Count >= 3
	Value = ""
	Value = SMGetNumBlockX(Astring,3)
	print " Y = ",Value
endif

if Count >= 4
	Value = ""
	Value = SMGetNumBlockX(Astring,4)
	print " I = ",Value
endif

if Count >= 5
	Value = ""
	Value = SMGetNumBlockX(Astring,5)
	print " J = ",Value
endif


'==================
' OR
'==================

print

if Count >= 2
	Value = ""
	Value = SMGetNumBlockX(Astring,2)
	print " X = ","X"+Value
endif

if Count >= 3
	Value = ""
	Value = SMGetNumBlockX(Astring,3)
	print " Y = ","Y"+Value
endif

if Count >= 4
	Value = ""
	Value = SMGetNumBlockX(Astring,4)
	print " I = ","I"+Value
endif

if Count >= 5
	Value = ""
	Value = SMGetNumBlockX(Astring,5)
	print " J = ","J"+Value
endif

print
print "=========Instances of X Values==============="
print

'A typical string for you with 2 values in it.
Astring = ""
Astring = "G00 X-32.931 Y-29.599 X-64.321"

int Instances = 0
'Count how many X's are in the string.
Instances = SMCountStrings(Astring,"X")

print
print " There are ",Instances,"instances of 'X' in the string ",Astring
print

'With a simple loop, we can get the X values by getting the first instance 
'in an ever decreasing string.

if Instances > 0

	int Loop

   'An every decreasing string with X values in it starting with the full string.
	MyString = Astring

	do
		Loop ++
		Instances = 0
		Instances = SMCountStrings(MyString,"X")
	  
		if Instances = 0 then break

		'print " There are ",Instances,"instances of 'X' in the string."

		MyString = SMGetAfterStringX(MyString,"X",1)
      'print
		'print " String after X instance ",MyString

		Value = ""
		Value = SMGetNumBlockX(MyString,1)
      print
		print " X value ",Loop,"is ",Value

	until Instances = 0

endif

print

print
print "=========Press any key to end==============="
print

waitcon
SMEndStringMap()
end

