C# Sharp Basic Algorithm Exercises: Check whether a string 'yt' appears at index 1 in a given string
C# Sharp Basic Algorithm: Exercise-17 with Solution
Write a C# Sharp program to check whether a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string.
Pictorial Presentation:
Sample Solution:
C# Sharp Code:
using System;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(test("Python"));
Console.WriteLine(test("ytade"));
Console.WriteLine(test("jsues"));
Console.ReadLine();
}
public static string test(string str)
{
return str.Substring(1, 2).Equals("yt") ? str.Remove(1, 2) : str;
}
}
}
Sample Output:
Phon ytade jsues
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to check whether two given integer values are in the range 20..50 inclusive. Return true if 1 or other is in the said range otherwise false.
Next: Write a C# Sharp program to check the largest number among three given integers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework