Possible duplicate:
String conversion in C #
I want a "camelize" string, for example:
- PARTS / ACCESSORIES โ Parts / Accessories
- HELLO WORLD / TEST โ Hello World / Test
- Hello World โ Hello World
Here is what I still have:
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 ||
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 the lines will not exceed 250 characters? Thanks
source
share