field() Function

The field() function returns a substring from a string expression, by specifying a delimiter and the desired occurrence.

Syntax

field(str.exp, search.delimiter, num.delimiters, num.substr

Parameter(s)

str.exp  

String from which the substring will be returned.

search.delimiter

Delimiter to search for. The delimiter is limited to a single character. Any additional characters are ignored.

num.delimiters 

Number of delimiters to skip, plus one, prior to substring extraction.

num.substr

Number of substrings separated by the specified delimiter to be returned.

Description

After executing the field() function, the col1() and col2() functions return the beginning and ending positions within the string at which the delimiters were found.

Example(s)

This causes all characters up to the first asterisk in gl.account to be assigned to the variable company.code. As a result, afterward, company.code contains the value, 02. col1() has a value of 0, and col2() has a value of 3.

gl.account = "02*4000*11"

company.code = field(gl.account,"*",1)

This causes all characters from the first to the second asterisk to be stored in the variable, acct.number, which contains the value, 4000.

acct.number = field(gl.account,"*",2)

See Also

col1() Function, col2() Function, BASIC Functions, Numeric Expressions, procread Statement, Statements and Functions, Substring Assignment, Substring Expressions, Substring Extraction, Substring Field Store, tclread Statement