Understanding the System String Type

As mentioned, String is a native data type in VB 2008. Like all intrinsic types, the VB 2008 String keyword actually is a shorthand notation for a true type in the .NET base class library, which in this case is System.String. Therefore, you are able to declare a String variable using either of these notations:

' These two string declarations are functionally equivalent.

Dim firstName As String Dim lastName As System.String

System.String provides a number of methods you would expect from such a utility class, including methods that return the number of characters in the string, find substrings within the current string, convert to and from uppercase/lowercase, and so forth. Table 3-5 lists some (but by no means all) of the interesting members.

Table 3-5. Select Members of System.String

Member of String Class

Meaning in Life

Chars

This property returns a specific character within the current string.

Length

This property returns the length of a string.

Compare()

This method compares two strings.

Contains()

This method determines whether a string contains a specific substring.

Equals()

This method tests whether two string objects contain identical character

Was this article helpful?

0 0

Post a comment