How to Ignore Case and Check if String contains Specified ... - SAP

[Pages:3]How to Ignore Case and Check if String contains Specified Substring in C#?

C# ? Ignore Case and Check if String contains Substring

To ignore case and check if specified substring value is present in the string str , use String.Contains(String, StringComparison) method. Prepare StringComparison object comp with StringComparison.OrdinalIgnoreCase. Call Contains method on the string str and pass the substring value , and string comparison comp objects as arguments.

If the substring is present inside the string, of course ignoring the case, then String.Contains() method returns True. Else, it returns False.

C# Program

using System; class Example {

static void Main(string[] args) { String str = "abcdefgh"; String value = "CD"; StringComparison comp = StringComparison.OrdinalIgnoreCase; Boolean result = str.Contains(value, comp); Console.WriteLine($"Does string contain specified substring? {result}");

} }

Output

Does string contain specified substring? True

Conclusion

In this C# Tutorial, we learned how to check if specified substring is present in a given string while ignoring the case during string comparison.

C# Math

C# Math.Abs() C# Math.Acos() C# Math.Acosh() C# Math.Asin() C# Math.Asinh() C# Math.Atan() C# Math.Atan2() C# Math.Atanh() C# Math.BigMul() C# Math.BitDecrement() C# Math.BitIncrement() C# Math.Cbrt() C# Math.Ceiling() C# Math.Clamp() C# Math.CopySign() C# Math.Cos() C# Math.Cosh() C# Math.DivRem() C# Math.Exp() C# Math.Floor() C# Math.FusedMultiplyAdd() C# Math.IEEERemainder() C# Math.ILogB() C# Math.Log() C# Math.Log10() C# Math.Log2() C# Math.Max() C# Math.MaxMagnitude() C# Math.Min() C# Math.MinMagnitude() C# Math.Pow() C# Math.Round()

C# Math.ScaleB() C# Math.Sign() C# Math.Sin() C# Math.Sinh() C# Math.Sqrt() C# Math.Tan() C# Math.Tanh() C# Math.Truncate()

C# Tutorial C# Tutorial C# List C# Dicionary

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download