C# String Starts With

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

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);

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


More Articles

© 2020 DotNetHeaven. All rights reserved.