String Conditions and Functions

You can use string conditions in IF/THEN and IF/THEN/ELSE statements to perform comparisons between strings.

Examples of the syntax are as follows:

IF s1 = s2 THEN
IF s1 < s2 THEN
IF s1 > s2 THEN

The following string functions are also available for you to use:

  • left
  • right
  • mid
  • strdate
  • concat
  • strstr

left, right, mid syntax

The left, right, and mid functions enable you to extract substrings from a string. The left function extracts a specified number of characters from the left of the string variable or field and returns the result as a string. The right function extracts a specified number of character from the right of the string variable and returns the result as a string. The mid function extracts from a specified position in the string to the right, for a specified number of characters. This is an example of how the statements are used.

string[10] s;
string[3] s1;
string[3] s2;
string[4] s3;
string[7] s4;

s = "abcdefghij";
s1 = left(s,3);
s2 = right(s,3);
s3 = mid(s,3,4);

strdate syntax

The strdate function converts a datetime type into a string using a format that you specify. This function allows you to include static characters such as a slash (/), which gives you access to full date support.

datetime d;
string[8] s;

strdate(d,"%y/%m/%d",s);

concat syntax

The concat function concatenates a specified number of characters from one string onto the end of another string. The following example demonstrates the syntax to concatenate five characters from string "s2" onto the end of string "s1":

string[10] s1,s2;
concat(s1,s2,5);

strstr syntax

The strstr function finds a substring inside a string. This function returns the position of the first instance of the designated substring. If this function does not find the specified substring inside the string, it returns a value of -1.

integer d;

d = strstr("hello", "el");