开发者

what is wrong in this string?

开发者 https://www.devze.com 2022-12-15 04:07 出处:网络
string.Format(\"{Find Name=\'{0}\'}\", name) it throws Except开发者_运维知识库ion at runtime saying input string was in wrong format. What is wrong in this string?You need to escape the \'{ characte
string.Format("{Find Name='{0}'}", name)

it throws Except开发者_运维知识库ion at runtime saying input string was in wrong format. What is wrong in this string?


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


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)


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

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


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


I think it should be:

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

精彩评论

暂无评论...
验证码 换一张
取 消