PARSE()

PARSE()

Top  Previous  Next

 

The PARSE() function matches a string against a pattern, inserting a delimiter between each pattern element.

 

 

Format

 

PARSE(string, pattern, delimiter)

 

where

 

stringevaluates to the string to be parsed against the supplied pattern.

 

patternevaluates to a template as described below.

 

delimiterevaluates to the character to be inserted between each pattern element. If delimiter is a null string, a field mark is used. If delimiter is more than one character, only the first character is used.

 

 

The PARSE() function matches string against pattern and returns a copy of string with the delimiter character inserted between each pattern element. If the string does not completely match the pattern, a null string is returned.

 

The pattern string consists of one or more concatenated items from the following list.

 

...Zero or more characters of any type
0XZero or more characters of any type
nXExactly n characters of any type
n-mXBetween n and m characters of any type
0AZero or more alphabetic characters
nAExactly n alphabetic characters
n-mABetween n and m alphabetic characters
0NZero or more numeric characters
nNExactly n numeric characters
n-mNBetween n and m numeric characters
"string"A literal string which must match exactly. Either single or double quotation marks may be used. Unlike the MATCHES operator, string must be enclosed in quotes otherwise each character is treated as a separate component.

 

The values n and m are integers with any number of digits. m must be greater than or equal to n.

 

The 0A, nA, 0N, nN and "string" patterns may be preceded by a tilde (~) to invert the match condition. For example, ~4N matches four non-numeric characters such as ABCD (not a string which is not four numeric characters such as 12C4).

 

A null string matches patterns ..., 0A, 0X, 0N, their inverses (~0A, etc) and "".

 

The 0X and n-mX patterns match against as few characters as necessary before control passes to the next pattern. For example, the string ABC123DEF matched against the pattern 0X2N0X matches the pattern components as ABC, 12 and 3DEF.

 

The 0N, n-mN, 0A, and n-mA patterns match against as many characters as possible. For example, the string ABC123DEF matched against the pattern 0X2-3N0X matches the pattern components as ABC, 123 and DEF.

 

The pattern string may contain alternative templates separated by value marks. The PARSE() function tries each template in turn until one is a successful match against string. If a match is found, the INMAT() function can be used to retrieve the value position within the pattern that matched.

 

The delimiter argument determines the character to be inserted between the portions of string that match each part of the pattern.

 

The PARSE() function returns a null string if no component of pattern matches string.

 

 

Example

 

TEL.NO = "01604-709200"

DISPLAY PARSE(TEL.NO, "0N'-'0N", "|")

 

This program fragment displays

01604|-|709200

 

 

See also:

Pattern Matching, MATCHFIELD()