2

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

thanks for help

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

7 Answers 7

6

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);
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

2

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

Comments

2

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);

Comments

2

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

Source: String.Format()

Comments

1

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

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

Comments

0

I sometimes use

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

That way the format string is more readable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.