开发者

how to ignore { character?

I would like to ignore { character in string is it possible ?

thanks for help

String.Format("functio开发者_运维问答n(s, e) {  {0}.PerformCallback(MyObject.GetSelectedItem().value); }", getClientName);


You have to double the curly braces in order to escape them:

String.Format(CultureInfo.InvariantCulture, @"
    function(s, e) {{
        {0}.PerformCallback(MyObject.GetSelectedItem().value);
    }}", getClientName);


You can escape the curly brace by typing {{ and it will display as one.


Replace your single '{' with a double '{{'.


The term you're after is 'delimit'. By replacing { with {{ and } with }} like so:

string.Format("function(s, e) {{  {0}.PerformCallback(MyObject.GetSelectedItem().value); }}", getClientName);


To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".

Source: String.Format()


If you by ignore, mean that you want to get rid of it, you can use the following code:

myString = myString.Replace("{","");


I sometimes use

char curly = '{';
String.Format("function(s, e), {0} {1}.PerformCallback(...)", curly, getClientName);

That way the format string is more readable.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜