473,396 Members | 1,743 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,396 software developers and data experts.

String Formatting

Hello,

I have a const string, who looks something like this:

const str = "abc {name: ohad phone: xxxxxx} {0} {1} {2}";

and i'd like to do this:

string a = string.Format(str, 1, 2, 3);

It's not working. I guess that the problem is that the c#'s Format method
looks at the string between the first {} like it is a parameter, like {0}
{1} {2}.
How can I solve it? I was working so hard to solve this problem, and
nothing.

please cc to my mailbox: oh**@usbphone.com

Thanks a lot,
Ohad Asor.
Nov 16 '05 #1
7 3068
Hi
const str = "abc {name: ohad phone: xxxxxx} {0} {1} {2}";


read MSDN
http://msdn.microsoft.com/library/en...formatting.asp

"you must specify two opening braces ("{{") in the fixed text to display one opening brace ("{"),
and specify two closing braces ("}}") "

--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Nov 16 '05 #2
Konnichi wa Ohad,

Nan to iimas ka ?
Kore wa Doitsu no Newsgroup desu ne !
Dewa mata ...

ciao Frank
--
Dipl.Inf. Frank Dzaebel [MCP C#]
Nov 16 '05 #3
Hi
const str = "abc {name: ohad phone: xxxxxx} {0} {1} {2}";


read MSDN
http://msdn.microsoft.com/library/en...formatting.asp

"you must specify two opening braces ("{{") in the fixed text to display one opening brace ("{"),
and specify two closing braces ("}}") "

--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Nov 16 '05 #4
Ohad wrote:
It's not working. I guess that the problem is that the c#'s Format method
looks at the string between the first {} like it is a parameter, like {0}
{1} {2}.
How can I solve it? I was working so hard to solve this problem, and
nothing.

You must escape the brackets by using two brackets instead of one when
they're not part of an format expression. Like this:
const str = "abc {{name: ohad phone: xxxxxx}} {0} {1} {2}";

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 16 '05 #5
Konnichi wa Ohad,

Nan to iimas ka ?
Kore wa Doitsu no Newsgroup desu ne !
Dewa mata ...

ciao Frank
--
Dipl.Inf. Frank Dzaebel [MCP C#]
Nov 16 '05 #6
Ohad wrote:
It's not working. I guess that the problem is that the c#'s Format method
looks at the string between the first {} like it is a parameter, like {0}
{1} {2}.
How can I solve it? I was working so hard to solve this problem, and
nothing.

You must escape the brackets by using two brackets instead of one when
they're not part of an format expression. Like this:
const str = "abc {{name: ohad phone: xxxxxx}} {0} {1} {2}";

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 16 '05 #7
You must escape the brackets by using two brackets instead of one when
they're not part of an format expression. Like this:
const str = "abc {{name: ohad phone: xxxxxx}} {0} {1} {2}";
上é¢åŒå¿—说的很对
Nov 16 '05 #8

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

Similar topics

5
by: Thomas Philips | last post by:
Consider the following simple dictionary e={1:'one', 2: 'two'} e >>>'one' However, If I attempt to print e using a formatted string print " %(1)s" %e, I get a KeyError: '1'
20
by: Pierre Fortin | last post by:
Hi! "Python Essential Reference" - 2nd Ed, on P. 47 states that a string format can include "*" for a field width (no restrictions noted); yet... >>> "%*d" % (6,2) # works as expected ' ...
5
by: rodney.maxwell | last post by:
Was doing some string formatting, noticed the following: >>> x = None >>> "%s" % x 'None' Is there a reason it maps to 'None'? I had expected ''.
0
by: David Rifkind | last post by:
I've seen some strange string formatting behavior on several XP and 2000 machines. I can get the same results with Graphics.DrawString, but the easiest way to see it is to put a label on a VB or...
0
by: Top Gun | last post by:
I have been finding difficulty in locating decent, in-depth information on a standard matter in the IT world... STRING FORMATTING. Particuarlly as it relates to C# (or .NET). The books I have give...
3
by: Franck | last post by:
hello, i'm looking for code (C# preferably) in order to change programmatically in a datagrid the string formatting expression of one bound colum thank you
7
by: Steven D'Aprano | last post by:
I have a sinking feeling I'm missing something really, really simple. I'm looking for a format string similar to '%.3f' except that trailing zeroes are not included. To give some examples: ...
27
by: fdu.xiaojf | last post by:
Hi, String formatting can be used to converting an integer to its octal or hexadecimal form: '307' 'c7' But, can string formatting be used to convert an integer to its binary form ?
7
by: sherifffruitfly | last post by:
Hi, God I hate datetime string formatting... How do I get a string of the form "04-Oct-2006", for example, from a DateTime object? Thanks a jillion, cdj
2
by: Tim Chase | last post by:
Is there an easy way to make string-formatting smart enough to gracefully handle iterators/generators? E.g. transform = lambda s: s.upper() pair = ('hello', 'world') print "%s, %s" % pair #...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.