Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Friday, August 10, 2012

Check if string contains a particular string in C#.Net

In this article we will discuss if a particular string is present inside a string in C#.Net. You can also check my last article on Extract first N words from a string with C#.

Suppose a string contains different strings separated by " | " character. From there we will find one particular string whether it exists or not.

Below is the code to check.
First we have to convert the string to string array with the string separator and then we will check  whether  the string is exists or not in the string array.

Full code:
 void CheckString()
    {
        string fullString = "SharePointDotNet|EnjoySharePoint|Fewlines4Biju";
     
        string searchString = "SharePointDotNet";
     
        char[] separator = new char[] { '|' };
     
        string[] s1 = fullString.ToLower().Trim().Split(separator);

        if (s1.Contains(searchString.ToLower().Trim()))
        {
            //The string is present !
        }
        else
        {
            //The string is not present !
        }
    }
You can also check an article on Remove HTML tags from string in C#.




0 on: "Check if string contains a particular string in C#.Net"