LibreOffice SymbolLibreOffice Symbol

Mangyaring suportahan kami!

Like operator

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

Icon ng Babala

Ang pare-pareho, function o bagay na ito ay pinagana sa pahayag Opsyon VBASupport 1 inilagay bago ang executable program code sa isang module.


Syntax:


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.

Uri ng pagbabalik:

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:

Icon ng Tala

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.

Halimbawa:


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