tags:

views:

133

answers:

5
string.Format("{Find Name='{0}'}", name)

it throws Exception at runtime saying input string was in wrong format. What is wrong in this string?

+2  A: 

try string.Format("Find Name='{0}'", name)

or try string.Format("{{Find Name='{0}'}}", name)

Rob Fonseca-Ensor
+12  A: 

You need to escape the '{ characters in String.Format:

string.Format( "{{Find Name='{0}'}}", name )

See the following for more details:

http://stackoverflow.com/questions/91362/how-to-escape-brackets-in-a-format-string-in-net

LBushkin
+3  A: 

Curly braces have a special meaning in formatting strings, and thus need to be escaped. Simply double the literal braces from { to {{ and } to }}:

string.Format("{{Find Name='{0}'}}", name)
Jørn Schou-Rode
+1  A: 

it should be "{{ Find Name = {0} }}"

Benny
A: 

I think it should be:

string.Format("Find Name='{0}'", name);
Sebastian Dietz