LibreOffice SymbolLibreOffice Symbol

Precisamos da súa axuda!

Like operator

Use the Like operator to compare a string with string pattern.

Icona Aviso

This constant, function or object is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.


Sintaxe:


Result = String1 Like String_pattern

Result: any logical value that records the comparison of the two strings.

String1: (required) the string you want to compare with String_pattern.

String_pattern: (required) any string expression conforming to the pattern-matching conventions.

Return type:

Boolean

Pattern matching conventions

The Like operator includes built-in pattern matching, making it a powerful tool for string comparisons. Its pattern-matching features allow the use of wildcard characters, character lists, or character ranges—individually or in combination—to match strings. The table below lists the characters allowed in patterns and what they match:

Icona Nota

The built-in pattern matching is not the same as the regular expressions used in other LibreOfficeDev modules.


Characters in pattern

Matches in string

?

Any single character.

*

Zero or more characters.

#

Any single digit (0-9).

[ character_list ]

Any single character in character_list. For example, any character in [zTrwqJkl] or in [A-P]

[ !character_list ]

Any single character not in character_list.


A group of one or more characters must be enclosed in square brackets ([]) and can match any single character in a string. It can include almost any character, including digits. Use a hyphen (-) to define a range of characters (for example [a-z]), where the hyphen separates the lower and upper bounds of the range.

Exemplo:


Sub ExampleLike
    Print "abc" Like "a*c"    ' Returns True.
    Print "badmington" Like "bad*"    ' Returns True.
    Print "M" Like "[A-E]"    ' Returns False.
    Print "M" Like "[!A-Z]"    ' Returns False.
    Print "Phone:12345678" Like "Phone:1234####"    ' Returns True.
End Sub