How to use C# string Contains
The String Contains method within the C# language serves as a valuable tool for determining the presence or absence of a specified sequence of character values within a given string. This method plays a crucial role in evaluating whether the target string includes the exact sequence of characters being searched for.
String str - input String for search
Returns:Boolean - Yes/No
If the str Contains in the String then it returns true
If the str does not Contains in the String it returns False
For ex: "This is a Test".Contains("is") return True
"This is a Test".Contains("yes") return False
Exceptions:System.ArgumentNullException : If the argument is null
When the Contains method is invoked, it thoroughly examines the contents of the string, scanning for the precise sequence of characters specified as the search criteria. If the sequence is found in its entirety, the method will yield a true result, indicating that the string indeed contains the exact sequence of characters being sought after. However, if even a single character within the specified sequence is not present within the string, the method will return false, indicating the absence of the desired character sequence.
Text
Using the Contains method in C#, programmers can effectively scrutinize the contents of a string and ascertain the presence or absence of a specific character sequence. This functionality empowers developers to design robust algorithms and implement conditional logic based on the presence or absence of certain character sequences within strings, enabling intricate and precise data processing.
Full Source C#When you run the C# program you will get the MessageBox with message "The string Contains() 'TOP' "
Conclusion
The Contains method in CSharp provides a valuable means of evaluating the presence or absence of a specified sequence of characters within a given string, offering programmers a reliable tool for building conditional logic and designing algorithms that depend on the existence of certain character sequences within strings.
- How to use C# string Clone
- How to use C# string Compare
- How to use C# string Concat
- How to use C# string Copy
- How to use C# string CopyTo
- How to use C# string EndsWith
- How to use C# string Equals
- How to use C# string Format
- How to use C# string IndexOf
- How to use C# string Insert
- How to use C# string Length
- How to use C# string Split
- Substring in C#
- How to validate a string using TryParse in C#
- How to C# String Null
- Generate random strings, alphanumeric strings and numbers