C Sharp. Design a program that accepts as an input a sentence in which all of th
ID: 3744023 • Letter: C
Question
C Sharp. Design a program that accepts as an input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string StopAndSmellTheRoses would be converted to Stop and smell the roses. C Sharp please. C Sharp. Design a program that accepts as an input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string StopAndSmellTheRoses would be converted to Stop and smell the roses. C Sharp please.Explanation / Answer
using System;
using System.Text.RegularExpressions;
namespace TestSplit
{
class MainClass
{
public static void Main (string[] args)
{
var r = new Regex(@"
(?<=[A-Z])(?=[A-Z][a-z]) |
(?<=[^A-Z])(?=[A-Z]) |
(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace);
string Str;
Console.Write("Enter a string ");
Str = Console.ReadLine();
Console.Write(Str);
Console.WriteLine( " {0}", r.Replace(Str, " "));
}
}
}
output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.