Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add { in String Format c# [duplicate]

Tags:

string

c#

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.

like image 739
L.E. Avatar asked Jan 31 '12 17:01

L.E.


People also ask

What is %N in format string?

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.

How do you use %d in strings?

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.

How do you write in string format?

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.


1 Answers

From this MSDN FAQ:

string s = String.Format("{{ hello to all }}");
Console.WriteLine(s);    //prints '{ hello to all }'
like image 182
M.Babcock Avatar answered Sep 19 '22 09:09

M.Babcock