String Formatting

O

Ohad

Hello,

I have a const string, who looks something like this:

const str = "abc {name: ohad phone: xxxxxx} {0} {1} {2}";

and i'd like to do this:

string a = string.Format(str, 1, 2, 3);

It's not working. I guess that the problem is that the c#'s Format method
looks at the string between the first {} like it is a parameter, like {0}
{1} {2}.
How can I solve it? I was working so hard to solve this problem, and
nothing.

please cc to my mailbox: (e-mail address removed)

Thanks a lot,
Ohad Asor.
 
?

=?ISO-8859-1?Q?Anders_Nor=E5s?=

Ohad said:
It's not working. I guess that the problem is that the c#'s Format method
looks at the string between the first {} like it is a parameter, like {0}
{1} {2}.
How can I solve it? I was working so hard to solve this problem, and
nothing.
You must escape the brackets by using two brackets instead of one when
they're not part of an format expression. Like this:
const str = "abc {{name: ohad phone: xxxxxx}} {0} {1} {2}";

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
G

Guest

Konnichi wa Ohad,

Nan to iimas ka ?
Kore wa Doitsu no Newsgroup desu ne !
Dewa mata ...

ciao Frank
 
G

Guest

You must escape the brackets by using two brackets instead of one when
they're not part of an format expression. Like this:
const str = "abc {{name: ohad phone: xxxxxx}} {0} {1} {2}";
上é¢åŒå¿—说的很对
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top