How to: Remove Parts of a String (Visual Basic)

The following code example removes all occurrences of one string from another string.

Example

This example uses the Replace function to replace each occurrence of the substring with an empty string. The result is a new string with the substrings removed.

The example assigns the return value of the Replace function to the string variable withoutParts. The original string, stored in withParts, is not changed.

Dim withParts As String = "Books and Chapters and Pages" 
Dim withoutParts As String = Replace(withParts, "and ", "")

Compiling the Code

Replace "Books and Chapters and Pages" with the string you want to manipulate.

See Also

Reference

Replace Function (Visual Basic)

String Data Type (Visual Basic)