Q:

Write a C# program to get a new string of two characters from a given string. The first and second character of the given string must be "P" and "H", so PHP will be "PH"

0

Write a C# program to get a new string of two characters from a given string. The first and second character of the given string must be "P" and "H", so PHP will be "PH"

Sample Output:

PH

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 Exercise.38 {
static void Main(string[] args)
        {
string str1 = "PHP Tutorial";
var result = "";

if (str1.Length >= 1 && str1[0] == 'P') 
result += str1[0];
if (str1.Length >= 2 && str1[1] == 'H')
result += str1[1];
Console.WriteLine(result);
        }
}

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