String.Format and Curley Braces

A

AMDRIT

Hello all,

I am trying my hand at RegEx and came across a tangent; curley braces upset
string.format expressions. Is there a way to escape them with out making
them an argument?

strTemp = string.format("This is my string }{") =Exception thrown
strTemp = string.format("This is my string {0}{1}","}"."{") = This is my
test string }{

my reason for useage:

Allow any alphanemeric value x to x+n times where x and x+n are passed in
values

string.format("\b[a-zA-Z0-9]{{0},{1}}\b", MinLen, MaxLen)

becomes

string.format("\b[a-zA-Z0-9]{0}{1},{2}{3}}\b","{", MinLen, MaxLen, "}")

Thanks
 
J

Jon Skeet [C# MVP]

AMDRIT said:
I am trying my hand at RegEx and came across a tangent; curley braces upset
string.format expressions. Is there a way to escape them with out making
them an argument?

strTemp = string.format("This is my string }{") =Exception thrown
strTemp = string.format("This is my string {0}{1}","}"."{") = This is my
test string }{

Yes - use {{ for a single opening brace and }} for a single closing
brace. For instance, "{{0}}" comes out as "{0}".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top