How to match a substring in a string ignoring case in C#

3 Answers

0 votes
using System;

public class MyClass {
	public static void Main(string[] args)
	{
	    string str = "C# C++ PYTHON C JAVA PHP";
	    string substring = "python";
	    
        Boolean result = str.Contains(substring, StringComparison.OrdinalIgnoreCase);
        
        Console.WriteLine(result);
    }
}




/*
run:
    
True
    
*/

 



answered Sep 30, 2022 by avibootz
0 votes
using System;

public class MyClass {
	public static void Main(string[] args)
	{
	    string str = "C# C++ PYTHON C JAVA PHP";
	    string substring = "python";
	    
        int index = str.IndexOf(substring, StringComparison.OrdinalIgnoreCase);
        
        Console.WriteLine(index);
    }
}




/*
run:
    
7
    
*/

 



answered Sep 30, 2022 by avibootz
0 votes
using System;
 
public class MyClass {
    public static void Main(string[] args)
    {
        string str = "C# C++ PYTHON C JAVA PHP";
        string substring = "python";

        if (str.IndexOf(substring, StringComparison.OrdinalIgnoreCase) > -1)
            Console.WriteLine("Match");
        else
            Console.WriteLine("Not match");
    }
}
 
 
 
 
/*
run:
     
Match
     
*/

 



answered Sep 30, 2022 by avibootz
...