Possible Duplicate:
How to escape brackets in a format string in .Net
string.format format string containing {
I was trying to format string like this, {Enum.Enum1,"Enum1String"} I tried this code
foreach (KeyValuePair<int, string> p in Helper.Dict)
{
// file.WriteLine(string.Format("{0} | {1}",p.Key,p.Value));
file.WriteLine(string.Format("{Enum.{0},\"{1}\"}", p.Value,p.Value));
}
but it doesn not work. How to add { in string format. I am thinking to use stringbuilder.
In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n.
The %d operator is used as a placeholder to specify integer values, decimals, or numbers. It allows us to print numbers within strings or other values. The %d operator is put where the integer is to be specified. Floating-point numbers are converted automatically to decimal values.
In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string. Parameter: The locale value to be applied on the format() method.
From this MSDN FAQ:
string s = String.Format("{{ hello to all }}");
Console.WriteLine(s); //prints '{ hello to all }'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With