1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
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);
}
|