Q:

Write a C# program to check if a string starts with a specified word

0

Write a C# program to check if a string starts with a specified word

Sample Output:

Input a string : Hello how are you?                                    
True

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Exercise34 {
  static void Main(string[] args)
        {
           string str; 
           Console.Write("Input a string : ");
           str = Console.ReadLine();
           Console.WriteLine((str.Length < 6 && str.Equals("Hello")) || (str.StartsWith("Hello") && str[5] == ' '));
        }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now