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

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

Svetlozar Angelov
  • 20,444
  • 6
  • 61
  • 67
viky
  • 16,807
  • 13
  • 69
  • 89

5 Answers5

12

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

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

See the following for more details:

How to escape braces (curly brackets) in a format string in .NET

Community
  • 1
  • 1
LBushkin
  • 125,412
  • 32
  • 212
  • 261
3

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
  • 36,791
  • 14
  • 84
  • 120
2

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

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

Rob Fonseca-Ensor
  • 15,335
  • 43
  • 57
1

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

Benny
  • 8,277
  • 7
  • 58
  • 91
0

I think it should be:

string.Format("Find Name='{0}'", name);
Sebastian Dietz
  • 5,507
  • 1
  • 30
  • 39