Programming Course in C# ¡Free!

Strings manipulation

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

Create a program that asks the user for a string and:


- Replaces all spaces with underscores (storing the result in a new string)
- Removes leading spaces (storing the result in another string)
- Removes trailing spaces (storing the result in another string)
- Replaces all lowercase A by uppercase A (storing the result in another string)

The program must display all the strings it generates.


Output



Solution


using System;
class Program
{
static void Main(string[] args)
{
Console.Write("Tell a string: ");
string Entry = Console.ReadLine();
string result;
result = Entry.Replace("a", "A");
Console.WriteLine(result);
Console.WriteLine(UppercaseFirst(Entry));

}

public static string UppercaseFirst(string s)
{
return char.ToUpper(s[0]) + s.Substring(1);
}
}