C# String Starts With

In this article we will discuss about how to use the starts with method in C#.
  • 3633

The StartsWith method returns true if a strings starts with a specified string. The following code snippet checks if a string starts with "Mahesh". 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string sentence = "Mahesh Chand is an author and founder of C# Corner";
            Console.WriteLine("Original String: {0}", sentence);
            string findString = "Mahesh";
            bool b = sentence.StartsWith(findString);
            Console.WriteLine("String starts with {0}: {1}", findString, b);
            Console.ReadLine();
        }
    }
}


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.