< Day Day Up > |
The string concatenation operator ( & ) takes two string operands and combines them into a single string. If either operand is not a string (or if they both are not strings), it will be converted to a string without requiring an explicit conversion, even if Option Strict is on. The result of a concatenation operation is a new string that represents the concatenation of the two operands.
One thing to remember is that because the concatenation operator returns an entirely new string, a series of concatenation operations may allocate quite a few new strings, which may have performance implications. When you are doing many concatenations, the type System.Text.StringBuilder can be used instead to make the concatenation faster. Dim Count As Integer Dim s As String Dim sb As New Text.StringBuilder() For Count = 1 To 10000 s &= CStr(Count) & "," Next Count Console.WriteLine(s) For Count = 1 To 10000 sb.Append(CStr(Count)) sb.Append(",") Next Count Console.WriteLine(s.ToString()) In this example, the second loop will be several times faster than the first. The Like operator determines whether a string matches a given pattern. The first operand is the string being matched; the second operand is a string representing the pattern to match against. In the simplest case, where the pattern contains no special matching characters , the Like operator is equivalent to the = operator. However, the following character sequences have special meanings when used in a pattern.
Two characters in a character list separated by a hyphen ( - ) specify a range of Unicode characters, starting with the first character and ending with the second character. If the second character is not later in the current thread's culture's sort order than the first character, a runtime error occurs. A hyphen that appears at the beginning or end of a character list specifies itself. To match the special characters left bracket ( [ ), question mark ( ? ), pound ( # ), and asterisk ( * ), the particular character must be enclosed in brackets. The right bracket ( ] ) cannot be used within a group to match itself, but it can be used outside a group as an individual character. The character sequence [] is considered to be the string literal "" . Some examples of the Like operator are the following. Dim r As Boolean r = "abc" Like "a?c" ' Result: True r = "abcdef" Like "a*f" ' Result: True r = "abc" Like "a[A-Z]c" ' Result: False r = "aBc" Like "a[A-Z]c" ' Result: True Character comparisons and ordering for character lists are dependent on the type of string comparisons being used. If binary comparisons are being used (i.e., Option Compare Binary ), character comparisons and ordering are based on the numeric Unicode values. If text comparisons are being used (i.e., Option Compare Text ), character comparisons and ordering are based on the current thread's culture.
|
< Day Day Up > |