How to VB.NET String.Contains()

The Contains method in the VB.NET String Class is a useful function that enables you to check whether a specified parameter string exists within another string. By invoking the Contains method, you can efficiently determine if a particular substring is present within a larger string, allowing you to perform conditional logic or extract relevant information based on the presence or absence of the target substring. This method provides a convenient and straightforward way to handle string manipulation and search operations in VB.NET.

System.String.Contains(String str) As Boolean
  1. String str - input String for search
  1. Boolean - Yes/No.

The Contains method in the VB.NET String Class is designed to provide a Boolean value indicating whether a specified substring exists within a given string. If the substring is found within the string, the method returns true, signifying that the substring is present.

Conversely, if the substring is not found, the method returns false, indicating that the substring does not exist within the string. For example, when using the Contains method with the string "This is a Test", searching for the substring "is" will result in a true value, confirming its presence. However, when searching for the substring "yes", the method will return false, as the substring is not found in the original string. This functionality allows for efficient and convenient substring detection in VB.NET programming.

System.ArgumentNullException :If the argument is null.
Full Source VB.NET
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim str As String str = "VB.NET TOP 10 BOOKS" If str.Contains("TOP") = True Then MsgBox("The string Contains() 'TOP' ") Else MsgBox("The String does not Contains() 'TOP'") End If End Sub End Class


The VB.NET String.Contains() method is used to determine whether a specified substring is present within a given string, returning a Boolean value indicating its existence or absence.