Optimize the string. Format + replace
I have this function. Visual studio profile tagged line with line. The formatting was just as hot and I was spending most of my time.
How can I write this loop more efficiently?
public string EscapeNoPredicate(string sz)
{
var s = new StringBuilder(sz);
s.Replace(sepStr, sepStr + sepStr);
foreach (char v in IllegalChars)
{
string s2 = string.Format("{0}{1:X2}", seperator, (Int16)v);
s.Replace(v.ToString(), s2);
}
return s.ToString();
}
+2
user34537
a source
to share
2 answers