You need to format an english sentence into a "headline format" (first letter capitalized).
String words = "this is a totally made-up sentence";
Char splitter = ' '
Capitalize(words, splitter);
splitter = '-'
Capitalize(words, splitter);
private static String Capitalize(String words, Char splitter)
{
String[] split;
split = words.Split(splitter);
words = String.Empty;
foreach(String part in split)
{
Char[] chars;
chars = part.ToCharArray();
if(chars.Length > 0)
{
chars[0] = ((new String(chars[0], 1)).ToUpper().ToCharArray())[0];
}
words += new String(chars) + splitter;
}
words = words.Substring(0, words.Length - 1);
return (words);
}
2 Kommentare zum Snippet