Pages

Saturday, March 16, 2013

C#: Check whether a string is substring of another string?


public void CheckForSubstring()
        {
            string str = "onetwothree";
            bool result = str.Contains("two");
            Console.WriteLine(result);  //returns True

            result = str.Contains("Two"); //returns False, bcoz C# is case sensitive
            Console.WriteLine(result);
        }

Output: True
              False  

No comments:

Post a Comment