Home VB.NET 1 VB.NET 2 VB.NET 3 VB.NET 4 VB.NET 5 VB.NET 6 VB.NET 7 VB.NET 8 VB.NET 9 VB.NET 10 VB.NET 11 VB.NET 12 VB.NET 13 VB.NET 14 VB.NET 15 VB.NET 16 VB.NET 17 About

VB.NET 10

Code, Design and Applications


VISUAL BASIC .NET CONCEPTS

Strings

The String data type represents a series of characters (each representing in turn an instance of the Char data type). An instance ofa string can be assigned to a literal value that represents a series of characters. For example:

Dim MyString As String

MyString = "This is an example of the String data type"

A String variable can also accept any expression that evaluates to a string. Examples are shown below:

Dim OneString As String

Dim TwoString As String

TwoString = OneString.Substring(5,3) ' Evaluates to "two".

OneString = "1"

TwoString = OneString & "1" ' Evalates to "11".

A string can be thought of as a series of Char instances, and the String type has built-in functions that allow you perform manymanipulations on a string that resemble the manipulations allowed by arrays. You may refer to a specific character in a stringthrough the Chars property, which provides a way to access a character by the position in which it appears in the string. For Example:

Dim myString As String = "ABCDE"

Dim myChar As Char

myChar = myString.Chars(3) ' The value of myChar is "C"

More Samples

INDEXOF

Dim myString As String = "ABCDE"

Dim myInteger As Integer

myInteger = myString.IndexOf("D") ' myInteger = 3

CONCAT

Dim aString As String = "A"

Dim bString As String = "B"

Dim cString As String = "C"

Dim dString As String = "D"

Dim myString As String

' myString = "ABCD"

myString = String.Concat(aString, bString, cString, dString)

LCASE UCASE TOUPPER TOLOWER

Dim myString As String = "UpPeR oR LoWeR cAsE"

Dim newString As String

' newString = "UPPER OR LOWER CASE"

newString = UCase(myString)

' newString = "upper or lower case"

newString = LCase(myString)

' newString = "UPPER OR LOWER CASE"

newString = myString.ToUpper

' newString = "upper or lower case"

newString = myString.ToLower

TRIM

Dim myString As String = "#####Remove those!######"

Dim oneString As String

OneString = myString.Trim("#")

REMOVE REPLACE

Dim aString As String = "This is My Str@o@o@ing"

Dim myString As String

Dim anotherString As String

' myString = "This is My String"

myString = aString.Remove(14, 5)

' anotherString = "This is Another String"

anotherString = myString.Replace("My", "Another")

Visual Basic .Net

INSERT

Dim aString As String = "This is My Stng"

' Results in a value of "This is My String".

myString = aString.Insert(13, "ri")

JOIN

Dim shoppingItem(2) As String

shoppingItem(0) = "Milk"

shoppingItem(1) = "Eggs"

shoppingItem(2) = "Bread"

shoppingList = String.Join(",", shoppingItem)

SPLIT

Dim shoppingList As String = "Milk,Eggs,Bread"

Dim shoppingItem(2) As Stringshopping

Item = shoppingList.Split(","c)

SUBSTRING

Dim aString As String = "Left Center Right"

Dim subString As String

' subString = "Center"

subString = aString.SubString(5,6)