SplitStr (Split Strings)

The SplitStr instruction is used to split out one or more strings or numeric variables from an existing string.

Syntax

SplitStr ( SplitResult, SearchString, FilterString, NumSplit, SplitOption )

Remarks

The splitting can be based on fixed delimiters (for example, commas) or semi-automatic (for example, reading numeric variables out of a string of mixed types as might be returned by a sensor). The FilterString and SplitOption help to define the array returned by the SplitStr instruction.

Parameters

SplitResult (Result of SplitStr)

An array or structure in which the split string will be stored.

Type: Variable Array or Structure

SearchString (Search String)

The string to evaluate.

Type: String or variable

FilterString (Filter String)

Provides a filter for the string(s) to be returned. For a FilterString using non-printable ASCII characters, use the CHR function and the appropriate ASCII code. For a full list of ASCII codes, see ASCII Codes and Characters.

Type: String or Variable

NumSplit (Maximum Number of Strings)

The maximum number of strings or values returned by the instruction.

Type: Constant

SplitOption (Split Option)

A code specifying the method used to split the string.

Code Description
0 NUMERIC – Numeric values are split out of the SearchString and stored into the array. Non-numeric characters are discarded. Delimiters are any characters but + - . 0 1 2 3 4 5 6 7 8 9 0 E). With this option, FilterString is ignored.
1 NON-NUMERIC – Non-numeric sub-strings (text strings) are split out of the SearchString and stored into the array. Numeric characters are discarded. Delimiters are . 0 1 2 3 4 5 6 7 8 9 0 E). With this option, FilterString is ignored.
2 SEARCHSTRING - SearchString is split and stored into the array based upon the occurrence of the entire FilterString.
3 SEARCHCHARS - SearchString is split and stored into the array based upon each occurrence of any character that is in FilterString.
4 HEADERFILTER - Any string succeeding FilterString is returned in SplitResult.
5 FOOTERFILTER -The number of values specified are parsed from the SearchString using the FilterString, or until the end of the SearchString is reached.
6 HEADERFILTERCHARS - Strings succeeding any character in the FilterString char list are returned in SplitResult. Redundant delimiters are treated as a single delimiter; for example, a string of “AA    BB    CC” with a Header Filter of “ “ (space) will be returned as “AA BB CC”. In addition, multiple delimiters can be specified; for example, “:;” will split a string based on the colon or semicolon.
7 FOOTERFILTERCHARS - Strings preceding any character in the FilterString char list are returned in SplitResult. Redundant delimiters are treated as a single delimiter. In addition, multiple delimiters can be specified; for example, “:;” will split a string based on the colon or semicolon.
8 NUMERICHEX - SearchString is split and stored in the array based upon the occurrence of hexadecimal numerics in the string (delimiters are any character but 0 1 2 3 4 5 6 7 8 9 0 A B C D E F). The hexadecimal value is stored in the array. With this option, FilterString is ignored.
1x Where X is one of the options above, right justify the resultant array, filling vacant elements with ClosedNAN Not a number. A data word indicating a measurement or processing error. Voltage overrange, SDI-12 sensor error, and undefined mathematical results can produce NAN. (if numeric) or a NULL string if a string.

For option 5, if a null string exists between two filter strings, a null string will be returned. For option 7, any null strings will be ignored.

Add 100 to any of the non-numeric options above to parse a string that includes quotes, with the quotes being omitted in the result.

String variables can be declared as only one or two dimensions; for example, String(x) or String(x,y). To begin reading or modifying a string at a particular location into the string, enter the location as a third dimension; for example, String(x,y,n) where n is the desired character. For example, given an array of strings Str(10,10), Str(2,2,n) refers to n character in the (2,2) element of the array. Use Str(1,1,n) for a scalar variable and Str(x,1,n) for a one dimensional array element.

The Mid instruction can also be used to split strings. It may be useful in cases where SplitStr will not work.

NOTE: String functions are case sensitive. Uppercase or lowercase can be used to convert to all one case prior to processing the string if desired.