strpart/3—determine the starting position of a partial string within a larger string
The strpart/3 function determines the starting position of a partial string within a larger string. The syntax for this function is as follows:
$POS=strpart($STR,$PART)
strpart/3 arguments
Argument | Mode | Type | Description |
---|---|---|---|
$STR | Input | STRING | Specifies the base string within which you want to determine the starting position of another partial string |
$PART | Input | STRING | Specifies the partial string for which you are trying to determine the starting position within $STR |
$POS | Output | INTEGER | Starting position of the partial string within $STR |
Use the strpart/3 function to determine the first position of the partial string specified in the $PART argument within the string specified in the $STR argument. The starting position is returned in $POS.
The starting position is determined by counting 1 as the first character of the string specified in $STR. If the partial string does not occur within the base string, the value 0 is returned as the position of $PART.
strpart/3 example
$ZPOS = strpart($E.mc_host,'.');
if ( $HLEN == 0 OR $ZPOS == 0 OR $ZPOS == $HLEN ) then
$E.mc_location = "Unknown";
else
$E.mc_location = substring($E.mc_host,$ZPOS,$HLEN-$ZPOS);