Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output '{' or '}' with string.format(...)

Tags:

string

c#

I bet that's an easy question for you, but searching SO or Google with { or } in the search string doesn't work very well.
So, let's say i wanna output {Hello World}, how do i do this using string.format(...)?

Edit:
looks like this:

string hello = "Hello World";
string.format("{0}", '{' + hello + '}');

would do the job, but that doesn't look very elegant to me. Is there a way to escape these characters inside the format string?

like image 535
Marcel B Avatar asked Mar 02 '10 08:03

Marcel B


People also ask

What is the datatype of output when format () is applied on string?

The values that exist within the str. format() method are essentially tuple data types and each individual value contained in the tuple can be called by its index number, which starts with the index number 0. These index numbers can be passed into the curly braces that serve as the placeholders in the original string.

How do you print a string output in Python?

In Python, there is no printf() function but the functionality of the ancient printf is contained in Python. To this purpose, the modulo operator % is overloaded by the string class to perform string formatting. Therefore, it is often called a string modulo (or sometimes even called modulus) operator.

What method is used to format string output in Python?

Python can format an object as a string using three different built-in functions: str() repr() ascii()

How do I return a formatted string in Java?

The Java String. format() method returns the formatted string by a given locale, format, and argument. If the locale is not specified in the String. format() method, it uses the default locale by calling the Locale.


1 Answers

Use {{ and }}. So your example would be string.Format("{{Hello World}}");

like image 134
Rory Avatar answered Oct 16 '22 01:10

Rory