المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Why does this not change my string?



C# Programming
08-16-2011, 03:42 AM
Hello.

I took this small function from anouther project, and I slightly modified it to work with a string object.

It accepts a string, and it should add a '-' for every nth charicture, as set by the code.

private void encodeString(string input) { for (int i = 0; i < input.Length-1; i++) { if ((i + 1) % 6 == 0) { input.Insert(i, "-"); } } }
It simply does not alter the string.

I simply want to pass string...

string test = ("00000000000000000000");
and end up with...

string test = ("00000-00000-00000-00000");
Thank you for any help with this.
Kind Regards,

Stephen