Wednesday, July 2, 2008

C# Page Title Method
Space Between Propercase Letters

protected string GetPageTitle(string fileName)
{
string title = String.Empty;
string fileNameWithoutExtension = String.Empty;

string[] titleParts = fileName.Split('.');
fileNameWithoutExtension = titleParts[0];

char[] c = fileNameWithoutExtension.ToCharArray();

int i = 0; // Don't put a Space in front of the First Character
foreach (char character in c)
{
if (Regex.IsMatch(character.ToString(), "[A-Z]") && i != 0)
{
title += " " + character;
}
else
{
title += character;
}
i++;
}

return title;
}

No comments:

Check This Out!

More Links to Good Information