¡Necesitamos su ayuda!

Operador Like [VBA]

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

Icono de aviso

Esta constante, función u objeto se activa mediante la instrucción Option VBASupport 1, colocada antes del código ejecutable del programa en un módulo.


Sintaxis:


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.

Devuelve tipo:

Boolean

Convenciones para la correspondencia de pautas

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:

Icono de nota

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


Caracteres en la pauta

Matches in string

?

Any single character.

*

Cero o más caracteres.

#

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.


Un grupo de uno o más caracteres debe ir entre corchetes ([]) y puede corresponder a cualquier carácter individual de una cadena. Puede incluir casi cualquier carácter, incluidos los dígitos. Utilice un guion (-) para definir un intervalo de caracteres (por ejemplo, [a-z]), donde el guion separa el límite inferior y el superior del intervalo.

Ejemplo:


Option VBASupport 1
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