Depends - did you define the varaiable
c
outside the loop? Did you mean to use
c4
instead?
char c4 = str[index];
string replace = string.Format(@"{0:x4}", (ushort)c4);
str = str.Replace(c.ToString(), replace);
Becomes:
char c4 = str[index];
string replace = string.Format(@"{0:x4}", (ushort)c4);
str = str.Replace(c4.ToString(), replace);