Equals
In the example, the output to the console can never happen because the period has been omitted from the
EndsWith test and the statement is thus False.
Equals
The Equals methodinherited from [Link] a means of determining, through the return of
True or False, if a certain String is equal in value to another String. Thus, if we think str1 is "X," the Equals
method allows us to determine if it is indeed "X." This method is convenient for testing values of Strings to
control flow in a methoda so−called sentinel construct. The syntax is as follows:
[Link](str2)
Now consider the following code (note that case is important):
Dim s1 As String = "Florida, we are T−10 and counting."
If [Link]("Florida, we are T−10 and counting.") Then
[Link]("True")
End If
Now you can also use the Is operator or the equal (=) operator to obtain the same results in the preceding
code. We only need to change one line, as follows:
If s1 Is "Florida, we are T−10 and counting." Then
Note It's a good idea to get into the habit of using the Is operator.
Format
The .NET Framework contains a String formatting method that provides standard formatting of a String's
characters, or the specified sub−String. It works by replacing the target String with the textual equivalent of a
numeric, date and time, or enumerator value. The legacy Visual Basic Format function has also been
wrapped by the .NET Framework, as demonstrated later in this section. See also "String Formatting," later in
this chapter.
Note The {0} specifier is the placeholder for a string of characters to be inserted into a String object. It works
like the C language's % specifier .
The types are formatted through the Format function applicable to the data type being rendered. The basic
syntax is as follows:
[Link]("The answer is {0:####}", answer)
Format is a static method, so the following syntax is also applicable:
Str1 = Format("The answer is {0:####}", answer)
The .NET formatting support also provides for custom formatting for more flexibility, which is illustrated
later in the section "String Formatting."
500