MANIPULATING STRINGS
INTRODUCTION
The following functions are available to manipulate strings in a document.
CONCATENATION (Combining strings)
Use the ampersand (&) character to combine two or more strings. For example:
PL:Title & ' ' & PL:FirstName & ' ' & PL:Name
(Note: See tip at the end of this Document)
SUB (Returns a portion of a string)
SUB(string,position,length)
|
String |
A string constant, variable or expression. |
|
Position |
A integer constant, variable, or expression. If positive, it points to a character position relative to the beginning of the string. If negative, it points to the character position relative to the end of the string (i.e., a position value of -3 points to a position 3 characters from the end of the string). |
|
Length |
A numeric constant, variable, or expression of number of characters to return. |
The SUB procedure parses out a sub-string from a string by returning length characters from the string, starting at position.
Return Data Type: STRING
Example:
SUB('ABCDEFGHI',1,1) returns 'A'
SUB('ABCDEFGHI',4,3) returns 'DEF'
String slicing
This is a “quicker” method of doing a SUB(). To take a "slice" of a string, put the number of the character you want between square brackets. If you want a range of characters separate the the beginning and ending character numbers with a colon.
Example:
Let’s say MEF:Field1 contains the string “Mortgagor”, a quick way is to check for a particular character is like this.
MEF:Field1[1] will return “M”
MEF:Field1[4] will return “t”
MEF:Field1[1:3] will return “Mor”
MEF:Field1[5:7] will return “gag”
UPPER(MEF:Field1[4]) will return “T”
As you can see, you can use UPPER(string) to return the uppercase of a particular string. For example if MEF:Field2 must contain a “Yes/No” response, you should use this to ensure it always works if either “YES” or “yes” or “Yes” is typed in by the User. For example:
[[IF(UPPER(MEF:Field2[1])='Y')]]You answered Yes to Field 2[[ENDIF]]
INSTRING
(Searches for a substring in a string)
INSTRING(substring,string [,step] [,start])
|
Substring |
A string constant, variable, or expression that contains the string for which to search. You should CLIP a variable substring so INSTRING will not look for a match that contains the trailing spaces in the variable. |
|
String |
A string constant, or the label of the STRING, CSTRING, or PSTRING variable to be searched. |
|
Step |
A numeric constant, variable, or expression which specifies the step length of the search. A step of 1 searches for the substring beginning at every character in the string, a step of 2 starts at every other character, and so on. If step is omitted, the step length defaults to the length of the substring. |
|
Start |
A numeric constant, variable, or expression which specifies where to begin the search of the string. If omitted, the search starts at the first character position. |
The INSTRING procedure steps through a string, searching for the occurrence of a substring. If the substring is found, the procedure returns the step number on which the substring was found. If the substring is not found in the string, INSTRING returns zero.
Example:
INSTRING('DEF','ABCDEFGHIJ',1,1) returns 4
INSTRING('DEF','ABCDEFGHIJ',2,1) returns 0
INSTRING('DEF','ABCDEFGHIJ',2,2) returns 2
INSTRING('DEF','ABCDEFGHIJ',3,1) returns 2
Other string functions
CENTER (return centered string)
CLIP (return string without trailing spaces)
FORMAT (return formatted numbers into a picture)
INLIST (return entry in list)
INSTRING (return substring position)
LEFT (return left justified string)
LEN (return length of string)
LOWER (return lower case)
RIGHT (return right justified string)
SUB (return substring of string)
UPPER (return upper case)
|
TIP The LEFT() function can be useful to left justify a string and remove unnecessary spaces. For example, if this Field is in a document Dear [[(PL:Title & ' ' & PL:FirstName & ' ' & PL:Name)]] it will work fine if the person has a title and a first name. It would look like this: Dear Mr Rick Jordan If, however, the Party has no title, there would be unnecessary spaces between “Dear” and “Rick” Dear Rick Jordan To prevent this, you can use the LEFT() function and left justify the entire Field. Dear [[(LEFT(PL:Title & ' ' & PL:FirstName & ' ' & PL:Name))]] and it will then look like this if there is no title Dear Rick Jordan and like this if there is no first name Dear Mr Jordan |