C# Program To Find The Count Of Sub-string "SHL" In A Given String



                                        
public class MyClass{    
    public static void Main(){    
        string str = "SHLfjsSHLfsjfshl".ToUpper();    
        int c = Regex.Matches(str, "SHL").Count;    
            
    Console.WriteLine(c);    
    }    
}  
                                          
                                          
                                        
public class MyClass{      
    public static void Main(){      
        string str = "SHLfjsSHLfsjfshl".ToUpper();        
       //Counter Keeping the track    
        int c = 0;      
        for(int i=0;i<str.Length;i++)      
        {      
            if(str[i]=='S'){      
                if(str[i+1]=='H'){      
                    if(str[i+2]=='L'){      
                        c+=1;      
                    }      
                }      
            }      
        }      
              
    Console.WriteLine(c);      
    }      
}