473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

String.Format and Curley Braces

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
Oct 10 '05 #1
1 2174
AMDRIT <am****@hotmail.com> wrote:
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}".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 10 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: The Crow | last post by:
if the reason for error is simple, excuse me. but i cant find what the reason is. Here is the snippet : string script = String.Format(@"<script src='common.js'...
6
by: Bruce Wiebe | last post by:
Hi all I have a string that contains a list of email addresses in the format {"X@y.com","x@y.com"} and i need to convert it to a string array in the same format so my array would loook like ...
1
by: AMDRIT | last post by:
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 =...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
4
by: MC | last post by:
In C, printf allows us to specify a runtime (non-constant) field width of a formatted value by using the * character. Is there something like that for System.String.Format? In C#, I find myself...
1
by: matt | last post by:
hello, i am accustomed to using the string.Format method in this way: string foo = string.Format("The formula is {0} * {1}", inputOne, inputTwo); but now i am trying to do one where i need...
7
by: Rick | last post by:
With String.Format, if I have an incorrect number of args specified for a format string, compile fails. How can I implement similar design-time functionality for my own string functions?
34
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is...
2
by: Alexander Vasilevsky | last post by:
This example string.Format("{ {0} }", "bla-bla-bla"); throw System.FormatException with message 'Input string was not in a correct format.' http://www.alvas.net - Audio tools for C# and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.