Splitting Variable Length Strings. Robelle Suprtool 5.7
ಜಾಹಿರಾತು
ಜಾಹಿರಾತು
164 • Suprtool 5.7 for MPE length of the string is the length of the field. If you do not want to retain all the spaces in a field, use one of the built-in trimming functions.
String constants are created with the exact length of the constant. For example, the string "abc" is three characters long and the string "a" is one.
When assigning the string expression to the target field, Suprtool pads the final string value with spaces to fill out the target field. String expressions longer than the target field generate an error.
>in testfile
>def a,1,10,byte
>ext a="I'm too long for this container"
Error: String is too long for the specified item
String Truncation
Suprtool produces an error if the string expression is longer than the target field. You cannot override this error with Set Ignore On. To help avoid the error, you may want to trim the expression of trailing spaces before assigning it to the target field. For example,
>extract new-field = $trim(a + b + c)
Upshifting Strings ($Upper)
Use the built-in function $upper to upshift all the characters of a string expression into uppercase characters. This function can be used to upshift a single field, a complicated string expression, or any subpart of an expression. Both ASCII and
Roman-8 characters are upshifted by $upper. For example,
>extract city-up = $upper(city)
>extract full-name = $upper(first + last)
Downshifting Strings ($Lower)
If you want to downshift all characters of a string expression to lowercase, use the built-in function $lower. This function can be used to downshift a single field, a complicated string expression, or any subpart of an expression. Both ASCII and
Roman-8 characters are downshifted by $lower. For example,
>extract city-lower-case = $lower(city)
>extract city-state = $lower(city + state)
Trimming Spaces Using $Trim, $LTrim, $RTrim
Use one of three built-in string functions to remove leading or trailing spaces from a string expression. The three functions are:
$Trim: Remove leading and trailing spaces from the string expression.
$LTrim: Remove leading spaces.
$RTrim: Remove trailing spaces.
Splitting Variable Length Strings
Suprtool can extract portions of a byte field based on the occurrence of certain characters.
Consider the following Data:
Suprtool Commands
Suprtool Commands
Armstrong/ Neil/ Patrick
Green/ Bob/ Miller
Edwards/ Janine/
Armstrong/Arthur/Derek
The $split function can extract each token into separate fields. The syntax for the
$split function is:
$split(Field,Start Character,Occurrence,End Character,Occurrence)
The following task will $split the data in the wholename into three separate fields.
The below task assumes that the file namefile is self-describing and has the field wholename in it:
>in namefile
>define lastname,1,30
>define firstname,1,20
>define middlename,1,20
>extract lastname = $split(wholename,first,"/")
>extract firstname=$trim($split(wholename,"/","/"))
>extract middlename=$trim($split(wholename,"/",2," ",2))
>out names,link
>xeq
The first extract statement tells Suprtool extract the bytes from the field wholename, starting at the beginning (first keyword), and stopping at the "/" character. The second extract statement, tells Suprtool to extract the bytes between the first occurrence of the "/" character to the next occurrence of the "/" character, and then that string is trimmed of spaces as it is nested within the $trim function.
The third and final extract statement tells Suprtool to extract the bytes beginning with the second occurrence of the "/" character to the second occurrence of the space character.
If the target field is not long enough to hold the data Suprtool will abort with an error. You can easily prevent this from happening on blank fields by nesting the
$split statement within a $trim or $rtrim function.
First/Last
The $split function also has a Last keyword, whereby you can split the field from a given occurrence of a character to the end of the field. So in the given example from above the extracting out of the middlename could be coded as such:
>extract middlename=$trim($split(wholename,"/",2,last))
The above means to extract out all the data from the second occurrence of the "/", to the end of the field and trim all spaces. Naturally as noted above we also have the
First keyword, which indicates the start of the field.
Unprintables
You can specify an unprintable character for Suprtool to use as the character to $split on, using the following syntax:
>extract middlename=$split(wholename,^9,2,last) which means that the split would start at the second occurrence of Decimal Nine, or the Tab character. Please note that for specifying unprintable characters you do not put in quotes.
Suprtool 5.7 for MPE• 165
ಡೌನ್ಲೋಡ್ ಮಾಡಿ
ಜಾಹಿರಾತು