Flexible NC programming
1.10 String operations
Job planning
1-32 Programming Manual, 03/2006 Edition, 6FC5398-2BP10-1BA0
Example: separating an input string into path and module names:
DEF INT PATHIDX, PROGIDX
DEF STRING[26] INPUT
DEF INT LISTIDX
INPUT = "/_N_MPF_DIR/_N_EXECUTE_MPF"
LISTIDX = MINDEX (EINGABE, "M,N,O,P") + 1 The value returned in LISTIDX is 3
because "N" is the first char from the
selection list in parameter INPUT,
searching from the beginning.
PATHIDX = INDEX (INPUT, "/") +1 ;Therefore: PATHIDX = 1
PROGIDX = RINDEX (INPUT, "/") +1 ;Therefore: PATHIDX = 1
;The SUBSTR function introduced in the
next section can be used to break up
variable INPUT into the components "Path"
and "Module":
VARIABLE = SUBSTR (INPUT, PATHIDX,
PROGIDX-PATHIDX-1)
;returning "_N_MPF_DIR"
VARIABLE = SUBSTR (INPUT, PROGIDX) ;returning "_N_EXECUTE_MPF"
1.10.7 Selection of a substring
Function
This functionality extracts a substring from a string. For this purpose, the index of the first
character and the desired string length (if applicable) are specified. If no length information is
specified, then the string data refers to the remaining string.
Programming
Syntax
STRING_ERG = SUBSTR (STRING,INT) Result type: INT
STRING_ERG = SUBSTR(STRING,INT, INT) Result type: INT
Semantics
In the first case, the substring from the position specified in the first parameter to the end of
the string is returned.
In the second case, the result string goes up to the maximum length specified in the third
parameter.
If the initial position is after the end of the string, the empty string (" ") will be returned.
A negative initial position or length triggers an alarm.
Example
DEF STRING [29] ERG
ERG = SUBSTR ("ACK: 10 to 99", 10, 2) ;Therefore: ERG == "10"