LOTUSSCRIPT LANGUAGE


Like operator
Determines whether a string expression matches a pattern string.

Syntax

stringExpr Like patternString

Elements

stringExpr


patternString Matching characters in a list

To match characters in a list, enclose the characters between square brackets with no spaces or other delimiters between characters (unless you want the space character to be part of the list). For example, [1, 2, 3, A, B, C] represents the characters 1, comma, space, 2, 3, A, B, and C (the redundant occurrences of the space and comma are ignored). But [123ABC] represents the characters 1, 2, 3, A, B, and C (with no space or comma character).

Matching characters in a range

To match characters in a range, separate the lower and upper bounds with a hyphen, as in [1-5]. Always specify the range in ascending sort order (A-Z rather than Z-A). Sort order is determined by the setting of Option Compare. When you specify multiple ranges, you donft have to separate them with anything: for example, [1-5A-C] contains the ranges 1-5 and uppercase A-C.

If binary comparison (Option Compare Binary) is in effect, LotusScript uses the international ANSI character collating sequence. This is the sequence of values Chr(0), Chr(1), Chr(2), .... It is the same on all LotusScript platforms. A range specified in ascending order will produce a valid pattern string. However, if Option Compare Case, NoCase, Pitch, or NoPitch is in effect, then the collating sequence order depends on the Lotus software that you are using. The order for alphanumeric characters will be the same as international ANSI, but using other characters to define a range may produce an invalid pattern string. If you define a range using nonalphanumeric characters, specify Option Compare Binary in your script to be certain of defining a valid pattern string.

Matching special characters

To match one of these characters, include it in a characters list:


Be sure to place the hyphen at the beginning of the list; if you're using the [!characters] format, the hyphen immediately follows the exclamation point, as in [!-123]. The other characters can appear anywhere in the characters list. For example, [-?A-Z] matches the hyphen, the question mark, and any uppercase letter from A through Z.

To match one of these characters, place the character anywhere within your wildcard specification except in a characters list or range:


For example, !,[1-6] matches the exclamation point, the comma, and any digit from 1 through 6.

Return value

If stringExpr matches patternString, the result is TRUE; if not, the result is FALSE. If either stringExpr or patternString is NULL, the result is NULL.

Usage

By default, the comparison is case sensitive. You can modify case sensitivity with the Option Compare statement.

Language cross-reference

@Like function in formula language

@IsMember function in formula language

@Matches function in formula language

Examples

Example 1

This example prints the two-digit numbers from 1 to 100 that end in 3 and don't begin with 2.

For x = 1 To 100
  If CStr(x) Like "[!2]3" Then Print x
Next x
' Output:
' 13 33 43 53 63 73 83 93

Example 2

This example uses Like as a validation formula for city and zip fields.

if doc.city(0) like "*[0-9]*" then messagebox _
  "city field contains a number"

if doc.zip(0) like "*[a-z,A-Z]*" then messagebox _  
  "zip code field contains a character"

Example 3

This example shows some ways you can test a string with Like to see if it contains a given substring:

' Make string comparison case-sensitive.
Option Compare Case
Dim anArray(1 To 6) As String
anArray(1) = "Juan"
anArray(2) = "Joan"
anArray(3) = "Alejandro"
anArray(4) = "Jonathan"
anArray(5) = "Andrea"
anArray(6) = "Jane"
UB% = UBound(anArray)

' Test each name in anArray$ to see if it contains a substring
' consisting of any characters followed by uppercase J
' followed by any characters followed by lowercase n followed
' by any characters.
For counter% = 1 to UB%
 If anArray(counter%) Like "*J*n*" Then
     Print anArray(counter%) & " " ;
 End If
Next
Print ""
' Output: Juan Joan Jonathan Jane

' Test each name in anArray$ to see if it contains
' a numeric character.
badRec% = 0
For counter% = 1 to UB%
 If anArray(counter%) Like "*#*" Then
     Print anArray(counter%) & " contains a numeral."
     badRec% = badRec% + 1
 End If
Next
If badRec% = 0 Then
 Print "No name contains a numeral."
End If
' Output: No name contains a numeral.

' Test the lowercase representation of each name in anArray$
' to see if it ends in a vowel.
For counter% = 1 to UB%
 If anArray(counter%) Like "*[aeiou]" Then
     Print anArray(counter%) & " " ;
 End If
Next
Print ""
' Output: Alejandro Andrea Jane

See Also