VB.NET String Notes

VB.NET String

String type

Strings store collections of characters. There are many different functions you can use on Strings in the VB.NET programming language. This selection of content details the String-based functions in this language.

These VB examples use the String type. They create, search and modify Strings.

Example

To start, this program demonstrates several concepts: how to declare and initialize a String; how to use a String literal such as "dot"; and how to concatenate strings with the plus operator and with the String.Concat method.

Program that uses String [VB.NET]

Module Module1
    Sub Main()
	Dim value As String = "dot"
	value = value + "net"
	Dim result As String = String.Concat(value, "perls")
	Console.WriteLine(result)
    End Sub
End Module

Output

dotnetperls
The VB.NET programming language

Core functions. These functions and subroutines are some of the most useful and widely used in the VB.NET language. Having an understanding of them is important for beginning VB.NET developers. This knowledge will carry over to other .NET languages as well.

Equals Format Insert Length Remove Replace String Constructor Substring ToCharArray ToStringNote

Manipulate strings. These examples manipulate Strings and arrays of Strings in various ways. Strings are often stored in arrays.

String Array Examples Sort String Tips Reverse String Loop Over String: For and For Each

Upper and lower

The .NET Framework provides us with many different ways to change the cases of characters in Strings. With the VB.NET language, we can use these functions or design our own, custom functions.

ToLower ToUpper Uppercase First Letter: String ToTitleCase Function

Split and Join

Split strings

Some of the more popular String functions in the VB.NET language include the Split and Join methods. We provide examples in the following tutorials.

Split Join

Search

If you need to search your String for a character pattern or a single character, these IndexOf and LastIndexOf functions are ideal.

Contains IndexOf IndexOfAny LastIndexOf LastIndexOfAny

Whitespace

Whitespace illustration

Some functions on the string type typically are used to handle whitespace characters; these functions include the Trim function and its variants TrimStart and TrimEnd.

Trim TrimEnd TrimStart NewLine LSet and RSet LTrim and RTrim

Ends and starts

Programming tip

Sometimes you need to see if one String ends with another String, or if one String starts with another String. To our relief, we can use the EndsWith and StartsWith functions.

EndsWith StartsWith

Related types

This section provides information

Some types are related to the String type but not the same. For example, the StringBuilder type is an alternative to strings, most useful when appending data together.

StringBuilder

Summary

The String type in the VB.NET language is powerful, but also has some limitations. In situations where you can improve performance by mutating an existing string, you will need to use an alternative type such as StringBuilder. Strings in the VB.NET language cannot be changed after they are created.

.NET