Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SplitStringSolution
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(CamelCase(" golf charlie mike foxtrot"));
- Console.WriteLine(CamelCase("bing bong boom"));
- Console.WriteLine(CamelCase("smart radio home enterprise "));
- Console.ReadKey();
- }
- public static string CamelCase(string str)
- {
- if (string.IsNullOrWhiteSpace(str))
- return str;
- //remove leading/trailing whitespace
- string newString = str.Trim();
- string finalString = "";
- // split the string into an array of substrings delimited by whitespace
- string pattern = @"\s+";
- String[] substrings = Regex.Split(newString, pattern);
- //capitalize first char of each substring
- // append the first substring letter and rest of the substring to newString
- foreach (var s in substrings)
- {
- finalString += s.Substring(0, 1).ToUpper() + s.Substring(1, s.Length - 1);
- }
- return finalString;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement