How to check if a string starts and ends with specific character in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main()
    {
        string str = "#c-sharp#";
   
        if (str[0] == '#' && str[str.Length - 1] == '#') 
            Console.Write("yes");
        else
            Console.Write("no");
    }
}



/*
run:

yes

*/

 



answered Apr 18, 2019 by avibootz

Related questions

...