0% found this document useful (0 votes)
4 views

complete-reference-vb_net_21

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

complete-reference-vb_net_21

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

String Formatting

Reformats Strings Format, FormatCurrency,


FormatDateTime,
FormatNumber,
FormatPercent
Retrieves the sub−String the specified number of characters from the left Left, Right
or right
Retrieves a String left− or right−aligned to a specified number of LSet, RSet
characters
Retrieves sub−Strings Mid
Strips spaces from Strings LTrim, RTrim, Trim
Finds a sub−String in a String InStr, InStrRev
Retrieves the Integer values associated with ANSI and ASCII characters Asc, AscW
Retrieves the character associated with the specified character code Chr, ChrW
Returns a Char value representing the character from the specified index GetChar
in the supplied String
Replaces one String with another Replace
Retrieves subsets (as arrays) of Strings from a filter applied to an array Filter
Retrieves an array containing the result of splitting a String Split
Retrieves the result of a join of two Strings Join
These String manipulation functions are just as useful in Visual Basic .NET as they are in classic VB. If you
can easily solve your problems using the native String manipulation methods, then you should prefer those so
that you lessen the burden of and reliance on legacy code. On the other hand, if one of these functions does
the job, don't hesitate to use it. I have used several of these functions in .NET applications to reduce the
amount of code I needed to write to achieve a certain result and I found no noticeable problems or overhead.

To use these functions, you need to reference the Visual Basic Run−Time Library.

String Formatting
As mentioned earlier, the .NET Framework provides three types of format providers. These provide
formatting of numeric Strings, data and time Strings, and Enumeration Strings. These "formatters" are
wired into the ToString methods of the fundamental data types that implement the IFormattable interface,
such as Int32 (Integer), Int64 (Long), Singles, Doubles, DateTime, Enumerator, and the like.

As demonstrated earlier in this chapter and in various places in this book, these formatters are also present in
the workings of the Console and String classes and other classes, such as those in the System.IO namespace,
that process text. See the "Format" section earlier in this chapter.

Classes that provide the formatter "masks" or "patterns, such as {00:00} and separator tokens and decimal
point tokens, are known as format providers. These classes implement the IFormatProvider interface.

The format provider is typically passed to an overloaded ToString method as defined by the IFormattable
interface. If no provider is passed, then the method can be coded to use a default format provider against the
arguments processed to it. In such situations where no providers are passed, the formatting is implicit to the
method, which obtains the mask and its tokens from one of the standard framework format providers.
However, ToString methods typically implement IFormattable to provide the support in one of their
overloaded variations (such as Console.WriteLine).

505

You might also like