I know I can append to a string but I want to be able to add a specific character after every 5 characters within the string
from this string alpha = abcdefghijklmnopqrstuvwxyz
to this string alpha = abcde-fghij-klmno-pqrst-uvwxy-z
I know I can append to a string but I want to be able to add a specific character after every 5 characters within the string
from this string alpha = abcdefghijklmnopqrstuvwxyz
to this string alpha = abcde-fghij-klmno-pqrst-uvwxy-z
You can use this:
string alpha = "abcdefghijklmnopqrstuvwxyz";
int length = alpha.Length;
for (int i = length - ((length - 1) % 5 + 1); i > 0; i -= 5)
{
alpha = alpha.Insert(i, "-");
}
Works perfectly with any string. As always, the size doesn't matter. ;)