Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ways to escape { in string.format function in vb

Tags:

vb.net

I am facing an issue with my code .

the thing is i want to escape { in the string.format function ...

Of course one way to escape it is to use {{ (2 curly braces)

Is there any other way possible to escape without using the double curly braces.

thanks

like image 202
Egalitarian Avatar asked Aug 18 '10 08:08

Egalitarian


People also ask

How do you escape a formatted string?

Answers. You can use a backslash to escape a formatting character: String. Format("{0:Save #\\%}", 100);

What is %s in string format?

The %s operator is put where the string is to be specified. The number of values you want to append to a string should be equivalent to the number specified in parentheses after the % operator at the end of the string value.

How do you use curly braces in string format?

Method 1: Using Double Curly Braces format string parser that the given curly braces must be escaped and considered as a part of the given text literal. This can be easily done by doubling the curly braces encompassing the string, that is using the following syntax: {{Serial No.}}

How do you escape curly braces in string format Java?

format (also used by VF apex:outputtext ) uses the Java MessageFormat class. And braces are escaped by enclosing in single quotes, which in apex must also be escaped by backslash.


2 Answers

Why would there be another solution? {{ is specified as the way of escaping braces in a format string... I can't see why the API designers would include another way.

Of course, you could also provide a format parameter and then populate it with a brace:

Dim text as String = string.Format("{0}{1}", "{", "}")

will give "{}" as a string, for example... but I can't see that this is a better solution.

Perhaps if you could say why you dislike the normal solution (double curly braces) we could advise you on an alternative - but there isn't one within the format specification "language" itself, as far as I'm aware.

like image 144
Jon Skeet Avatar answered Oct 01 '22 20:10

Jon Skeet


No, unfortunately it is not possible.

like image 35
dalle Avatar answered Oct 01 '22 20:10

dalle