Char and String Data Types

 <  Day Day Up  >  

The Char and String data types are used to represent textual values. The Char data type represents a single character, while the String data type represents a string of characters. The characters stored in a Char or String variable are encoded using the Unicode UTF-16 encoding, which means that each character in a variable of type Char or String is encoded using a two-byte integer value defined by the Unicode 3.0 Specification. The numeric encoding is mostly important when dealing with characters that do not have actual text representations (such as the carriage return character) or that cannot be typed or viewed on a particular machine.

The default value of the Char data type is the value ChrW(0) , also called the null character . The default value of the String data type is the literal Nothing , because String is a reference type (this is covered in more detail in Chapter 9, Classes and Structures). However, a String value of Nothing is considered to be the same as the literal "" by all the comparison operators as well as all the Visual Basic .NET runtime methods .

Character and String Literals

A string literal is just a series of characters surrounded by double quote ( " ) characters. All characters between the beginning and ending double quotes are considered part of the literal. Two embedded double quote characters next to each other are interpreted as a single double quote character and do not end the literal. A character literal is just a string literal with one character in it, followed by the character "c." The following shows some examples of character and string literals.

 Dim a, b, c As String Dim d, e, f As Char a = "The quick brown fox jumped over the lazy dog." b = "This literal contains a ""quoted"" string." c = "First line" & ChrW(&HD) & "Second line" d = "a"c e = """"c  ' This literal is the character "double quote" f = ChrW(&H20AC) 

The examples also use the ChrW function to represent characters that have no textual representation. In the example, the variable c contains a string with a carriage return in the middle of it, while the variable f contains the Euro character graphics/03inl01.gif .

 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net