Does anybody know how to capitalize every third letter of a string in C# ? I loop through the whole string with a for loop, but I can't think of the sequence right now.
Thanks in advance
I suspect you just want something like this:
// String is immutable; copy to a char so we can modify that in-place
char chars = input.ToCharArray();
for (int i = 0; i < chars.Length; i += 3)
chars[i] = char.ToUpper(chars[i]);
// Now construct a new String from the modified character array
string output = new string(chars);That assumes you want to start capitalizing from the first letter, so "abcdefghij" would become "AbcDefGhiJ". If you want to start capitalizing elsewhere, just change the initial value of i.