[an error occurred while processing this directive]
Forms Processor Advanced Commands
Contents   Index of Commands   Search the Forms Processor Docs   
substr Extracts a portion of a string, could be used with index to break up a slurped variable, that has multiple lines, into multiple variables.

$output = substr ($string, start, length);

Example:

# parse a known length input file
# the file is 3 lines long

# get the 3 line file into $data

&slurp("data","www/data/datafile.dat");

# find the offset of the first linefeed

$offset = index($data,"\n",0);

# extract from character 0 to the linefeed

$name = substr($data,0,$offset);

# extract everything from the character after the linefeed until the end of the # string into the $data variable again, so that it resets the zero character, 
# effectively removing all of the data until there is none left

$data=substr($data,$offset+1,length($data)-$offset);


$offset = index($data,"\n",0);
$street = substr($data,0,$offset);
$data=substr($data,$offset+1,length($data)-$offset);

$offset = index($data,"\n",0);
$city_state_zip = substr($data,0,$offset);
$data=substr($data,$offset+1,length($data)-$offset);

format screen

$name you live at:<br>
$street<br>
($city_state_zip)
.





See also:  index($string,$substr,start) function  length($string) function  &slurp("variable","filename") function [an error occurred while processing this directive]