Quantcast
Channel: Chaminda's DevOps Journey with MSFT
Viewing all articles
Browse latest Browse all 339

string.Format & { }

$
0
0

C# developers often use string.Format in handling string. string.Format the { and } is used as a special character to identify the parameters.

For example:

scrollDepth = “10”

string.Format("DOWN {0}",scrollDepth)  generates a string DOWN 10.

But what if a { should be used as a value in the string. Is there a way to include { in the string?

To escape a { you can {{. So if you want to get the resultant string as “{DOWN 10}” the syntax to use is

string.Format("{{DOWN {0}}}",scrollDepth)


Viewing all articles
Browse latest Browse all 339

Trending Articles