Introduction : In this tutorial we will check whether the word contains in string or sentence or not using Contains() method of string class in .NET Framework using C# and vb.net code example.
Contains() method of string class will check the given word or string match with any word or string in the particular sentence or string or word.
Contains () method will return boolean value true or false. If the given string or word contains against with a string or sentence it will return Contains else it will return False.
C# Code sample: using System;
namespace DotNetSparkTutorials
{
class Program
{
static void Main(string[] args)
{
string myString = "DotNetSpark";
string myContainsString = "DNS";
//Output or Result
Console.WriteLine(myString.Contains(myContainsString));
//Wait for input
Console.ReadLine();
}
}
}
VB.NET Code example: Namespace DotNetSparkTutorials
Class Program
Private Shared Sub Main(args As String())
Dim myString As String = "DotNetSpark"
Dim myContainsString As String = "DNS"
'Output or Result
Console.WriteLine(myString.Contains(myContainsString))
'Wait for input
Console.ReadLine()
End Sub
End Class
End Namespace
|