Evenimente
Construiți aplicații și agenți AI
17 mar., 21 - 21 mar., 10
Alăturați-vă seriei de întâlniri pentru a construi soluții AI scalabile bazate pe cazuri de utilizare din lumea reală cu colegi dezvoltatori și experți.
Înregistrați-vă acumAcest browser nu mai este acceptat.
Faceți upgrade la Microsoft Edge pentru a profita de cele mai noi funcții, actualizări de securitate și asistență tehnică.
If you want to find out if an expression of the String Data Type satisfies a pattern, then you can use the Like Operator.
Like
takes two operands. The left operand is a string expression, and the right operand is a string containing the pattern to be used for matching. Like
returns a Boolean
value indicating whether the string expression satisfies the pattern.
You can match each character in the string expression against a specific character, a wildcard character, a character list, or a character range. The positions of the specifications in the pattern string correspond to the positions of the characters to be matched in the string expression.
Put the specific character directly in the pattern string. Certain special characters must be enclosed in brackets ([ ]
). For more information, see Like Operator.
The following example tests whether myString
consists exactly of the single character H
.
Dim sMatch As Boolean = myString Like "H"
Put a question mark (?
) in the pattern string. Any valid character in this position makes a successful match.
The following example tests whether myString
consists of the single character W
followed by exactly two characters of any values.
Dim sMatch As Boolean = myString Like "W??"
Put brackets ([ ]
) in the pattern string, and inside the brackets put the list of characters. Do not separate the characters with commas or any other separator. Any single character in the list makes a successful match.
The following example tests whether myString
consists of any valid character followed by exactly one of the characters A
, C
, or E
.
Dim sMatch As Boolean = myString Like "?[ACE]"
Note that this match is case-sensitive.
Put brackets ([ ]
) in the pattern string, and inside the brackets put the lowest and highest characters in the range, separated by a hyphen (–
). Any single character within the range makes a successful match.
The following example tests whether myString
consists of the characters num
followed by exactly one of the characters i
, j
, k
, l
, m
, or n
.
Dim sMatch As Boolean = myString Like "num[i-m]"
Note that this match is case-sensitive.
Like
treats the sequence []
as a zero-length string (""
). You can use []
to test whether the entire string expression is empty, but you cannot use it to test if a particular position in the string expression is empty. If an empty position is one of the options you need to test for, you can use Like
more than once.
Call the Like
operator twice on the same string expression, and connect the two calls with either the Or Operator or the OrElse Operator.
In the pattern string for the first Like
clause, include the character list, enclosed in brackets ([ ]
).
In the pattern string for the second Like
clause, do not put any character at the position in question.
The following example tests the seven-digit telephone number phoneNum
for exactly three numeric digits, followed by a space, a hyphen (–
), a period (.
), or no character at all, followed by exactly four numeric digits.
Dim sMatch As Boolean =
(phoneNum Like "###[ -.]####") OrElse (phoneNum Like "#######")
Feedback pentru .NET
.NET este un proiect open source. Selectați un link pentru a oferi feedback:
Evenimente
Construiți aplicații și agenți AI
17 mar., 21 - 21 mar., 10
Alăturați-vă seriei de întâlniri pentru a construi soluții AI scalabile bazate pe cazuri de utilizare din lumea reală cu colegi dezvoltatori și experți.
Înregistrați-vă acumInstruire
Modul
Evaluate Boolean expressions to make decisions in C# - Training
Learn the operators and techniques required to evaluate and compare values in your decision statements.
Documentație
Learn more about: Like Operator (Visual Basic)
Comparison Operators (Visual Basic)
Learn more about: Comparison Operators in Visual Basic
Concatenation Operators in Visual Basic
Learn more about: Concatenation Operators in Visual Basic