Friday, July 8, 2011

Strings

String variables hold groups of Unicode characters. A string can contain up to
about 2 billion (2 ^ 31) Unicode characters. As you have seen, you now assign a
string to a variable using double quotes:
Dim message as String
message = "Help"
and the simplest way to concatenate (join them together) is to use the &. The older will also work, but can lead to major problems if you leave Option Strict off, so
we do not recommend using a + sign for string concatenation. The older way to
identify string variables (which are occasionally still used for temporary variables)
is to use a dollar sign ($) at the end of the variable name: aStringVariable$.
CAUTION Rather than being base type, strings in VB .NET are instances of the
String class. We offer more on their subtleties in the Chapter 4, but here is a hint
of what you need to know to use VB .NET efficiently: every time you make a
change to a string in VB .NET, a new string must be created. Because this could
cause a big performance penalty whenever a string needs to be repeatedly
changed, VB .NET comes with a StringBuilder class to manipulate strings that
require change (such as picking up data from a buffer and stringing it together
in a variable).
NOTE VB .NET does not support fixed-length strings as did earlier versions of VB.
String Functions
You have access to all the traditional VB6 string functions, such as Left, Right, Mid,
and so on, but note that the versions of these functions that end with $ are now
gone. The most important functions in the String class that can be used to replace
the VB6 string functions are summarized in Table 3-5. (Keep in mind that, if you
have to modify a string repeatedly with Mid, such as in a loop, you should use the
StringBuilder class described in Chapter 4.) Note that some of these methods rely
on arrays, which we cover later in this chapter.
Table 3-5. String Functions in the VB Compatibility Layer
FUNCTION DESCRIPTION
Asc Returns the character code corresponding to the first letter in
a string.
Chr Converts a number to Unicode.
Filter Takes a string array and a string to search for, returns a onedimensional
array containing all the elements that match the
search text.
GetChar Returns a Char representing a character from a specified index
in a string. The index for GetChar begins with 1. Example:
GetChar("Hello", 2) returns a Char containing the character “e.”
InStr Returns the position of the first occurrence of one string
within another.
InStrRev Returns the position of the last occurrence of one string
within another.
Join Lets you build a larger string out of smaller strings.
LCase Converts a string to lowercase.
Left Finds or removes a specified number of characters from the beginning
of a string.
Len Gives the length of a string.
LTrim Removes spaces from the beginning of a string.
Mid Finds or removes characters from a string.
Replace Replaces one or more occurrence of a string inside another.
Right Finds or removes a specified number of characters from the end of
a string.
RTrim Removes spaces from the end of a string.

No comments:

Post a Comment

This is Good Computer Information Blog.they will give
best information about computer.