can someone explain why this doesnt work:
string f = string.Format("\\x{0:00}{{0}}", 5);
string o = string.Format(f, "INSERT TEXT");
System.Diagnostics.Debug.WriteLine(f + " : " + o);
Output is:
\x05{0} : \x05INSERT TEXT
why does the \x05 not get replaced?
解决方案
The format for the argument should be set in the format specifier, otherwise you're just inserting a literal "\x". Like this:
// "5" as a lowercase 2-digit hex
string f = string.Format("{0:x2}{{0}}", 5);
Don't confuse how you represent a hex literal in source code with what you would print in a formatted string, they are different things.