If starts with lower case
Given a string, write a method that checks if each word in the string starts with lower case and if so, removes this letter from the string.
Expected input and output
IfStartsWithLowerCase("Alfa Beta gamma") → "Alfa Beta amma"
using System;
namespace CSharpExercises.Exercises.Library_functions
{
class IfStartsWithLowerCaseTask
{
public static string IfStartsWithLowerCase(string word)
{
string[] words = word.Split(' ');
for (int i = 0; i < words.Length; i++)
{
if (Char.IsLower(words[i][0]))
{
words[i] = words[i].Substring(1);
}
}
return String.Join(" ", words);
}
public static void Main()
{
Console.WriteLine(IfStartsWithLowerCase("tthis iis ffake ssentence.")); // this is fake sentence.
Console.WriteLine(IfStartsWithLowerCase("Praesent vitae convallis purus.")); // Praesent itae onvallis urus.
Console.WriteLine(IfStartsWithLowerCase("1 2 3 7 8 9 a b c x y z")); // 1 2 3 7 8 9
}
}
}