Working with Strings
You have already seen some examples using string @Functions. The example in the section "Converting Time-Date Values" used @Middle() , @Trim() , and @RightBack() . String functions can locate strings, extract parts of text strings (substrings), trim strings, convert data types to string, compare strings, determine their length, modify strings, and more. Table 12.8 lists some of the commonly used string @Functions.
Table 12.8. String @Functions
@Function | Purpose |
---|---|
Locating Substrings Within Strings | |
@Begins() | Determines whether a string begins with another string |
@Contains() | Determines whether a string contains another string |
@Ends() | Determines whether a string ends with another string |
Extracting Substrings from Strings | |
@Left() | Returns leftmost characters of a string, searching from left to right |
@LeftBack() | Returns leftmost characters of a string, searching from right to left |
@Middle() | Returns characters from the middle of a string, searching from left to right |
@MiddleBack() | Returns characters from the middle of a string, searching from right to left |
@Right() | Returns rightmost characters of a string, searching from left to right |
@RightBack() | Returns rightmost characters of a string, searching from right to left |
Comparing Strings | |
@Like() | Compares two strings (similar to @Match() but is ANSI SQL “compliant) |
@Matches() | Compares two strings |
Manipulating Strings | |
@Length() | Returns the length of a string |
@LowerCase() | Converts a string to lowercase |
@ProperCase() | Converts a string to proper case, capitalizing the first letters of words |
@UpperCase() | Converts a string to uppercase |
@Repeat() | Repeats a string |
@ReplaceSubString() | Replaces elements of a string |
@Text() | Converts other data types to text strings |
@Trim() | Removes leading and trailing blanks |
The function for converting dates in the date string format, May 22, 2002, to the standard month/date/year format 05/22/2002 uses several string @Functions. First, the string is trimmed in case the users put extra spaces into the field by jcDate := @Trim(cCreatedDate) . Next, using @If(@Contains(jcDate; "Jan") ; "01"... , you obtain the month number. The statement @Middle(jcDate; " "; ",") retrieves the day of the month by extracting the value between the space after the month and the comma. To retrieve the year, @RightBack(jcDate; ", ") was used, extracting anything to the right of the comma and space. You can also use @Right(jcDate; 4) to accomplish the same thing.
CAUTION
Note that for this formula to work properly, the initial value must be entered in the correct format.