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

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "c# java c php python c#";
        
        if (s.StartsWith("c#") && s.EndsWith("c#"))
            Console.WriteLine("yes");
        else
            Console.WriteLine("no");
    }
}
 
 
 
 
/*
run:
 
yes
 
*/

 



answered Nov 16, 2019 by avibootz

Related questions

...