Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is wrong in this string?

Tags:

string

c#

format

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

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

like image 787
viky Avatar asked Jul 11 '26 00:07

viky


2 Answers

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

like image 86
LBushkin Avatar answered Jul 13 '26 12:07

LBushkin


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)
like image 41
Jørn Schou-Rode Avatar answered Jul 13 '26 14:07

Jørn Schou-Rode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!