string search: contains, start with, end with

We can use Contains method from string to search a substring.


using System;

class Sample
{
    public static void Main()
    {
        string s = "java2s.com";

        Console.WriteLine(s.Contains("java"));
    }
}

The output:


True

In the same way we can use StartWith, EndWith methods.


using System;

class Sample
{
    public static void Main()
    {
        string s = "java2s.com";

        Console.WriteLine(s.StartsWith("java"));
        Console.WriteLine(s.EndsWith("java"));
    }
}

The output:


True
False
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.