String Formatting

  • Thread starter Thread starter Ohad
  • Start date Start date
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.
 
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/
 
Konnichi wa Ohad,

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

ciao Frank
 
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}";
上é¢åŒå¿—说的很对
 
Back
Top