Possible Duplicate:
Converting string in C#
I want to “camelize” a string, for example:
- PARTS/ACESSORIES -> Parts/Accessories
- HELLO WORLD/TEST -> Hello World/Test
- Hello World -> Hello World
Here’s what i have so far:
public static string Camelize(this string str)
{
if (String.IsNullOrEmpty(str)) return "";
var sb = new StringBuilder();
char[] chars = str.ToLower().ToCharArray();
bool upper = true;
// ' ', '-', '.', '/'
for (int i = 0; i < chars.Length; ++i)
{
char c = chars[i];
if (i == 0 || //First char
chars[i - 1] == ' ' ||
chars[i - 1] == '-' ||
chars[i - 1] == '.' ||
chars[i - 1] == '/'
) upper = true;
if (upper)
sb.Append(Char.ToUpper(c));
else
sb.Append(c);
upper = false;
}
return sb.ToString();
}
Is there any way to improve this method, also I know that strings will not exceed 250 chars?
Thanks
How about: