How to compare case insensitive string in C#

2 Answers

0 votes
using System;
 
class CompareCaseInsensitiveString_CSharp
{
    static void Main(string[] args)
    {
        string s1 = "c# JAVA", s2 = "C# java";

        if (s1.IndexOf(s2, StringComparison.OrdinalIgnoreCase) >= 0)
            Console.WriteLine("Equal");
        else
            Console.WriteLine("Not Equal");
    }
}


 
/*
run:
    
Equal
       
*/


 



answered Mar 31, 2017 by avibootz
edited Aug 23, 2024 by avibootz
0 votes
using System;
using System.Text.RegularExpressions;

class CompareCaseInsensitiveString_CSharp
{
    static void Main(string[] args)
    {
        string s1 = "c# JAVA", s2 = "C# java";

        bool b = Regex.IsMatch(s2, s1, RegexOptions.IgnoreCase);
 
        if (b) {
            Console.WriteLine("Equal");
        }
        else {
            Console.WriteLine("Not Equal");
        }
    }
}


 
/*
run:
    
Equal
       
*/

 



answered Mar 31, 2017 by avibootz
edited Aug 23, 2024 by avibootz

Related questions

1 answer 160 views
2 answers 211 views
1 answer 129 views
129 views asked Sep 27, 2022 by avibootz
1 answer 225 views
1 answer 133 views
1 answer 147 views
...