C# - Add space before upper case letter in a text
C# - Add space before upper case letter in a text
CODE
using System;
class Program
{
public static void Main()
{
string text = "HiHowAreYou";
string modifiedText = AddSpaceBeforeUpperCaseLetter("HiHowAreYou");
Console.WriteLine("{0} ==> {1}", text, modifiedText);
Console.ReadKey();
}
private static String AddSpaceBeforeUpperCaseLetter(String text)
{
String modifiedText = "";
if (text == "")
Console.WriteLine("The Input Text is blank.");
else
{
modifiedText = text[0].ToString();
for (int i = 1; i < text.Length; i++)
{
//The ASCII value of 'A' is 65 and 'Z' is 90
if ((text[i] > 64) && (text[i] < 91))
{
modifiedText = modifiedText + " " + text[i];
}
else
{
modifiedText += text[i];
}
}
}
return modifiedText;
}
}
Comments
Post a Comment