473,883 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MC++ String::Format?

The first three of these statements work. The fourth doesn't.

String::Format( "{0}{0}{0}{ 0}", S"");
String::Format( "{0}{1}{0}{ 0}", S"", S"");
String::Format( "{0}{1}{2}{ 0}", S"", S"", S"");
String::Format( "{0}{1}{2}{ 3}", S"", S"", S"", S"");

Question #1: Why?

Question #2: What is the simplest way to get this to work. I would
prefer to keep this statement on one line as opposed to separate
statements to declare, populate, and use a parameter array variable.
Nov 17 '05 #1
7 1643
"Tommy Vercetti" <ve*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
The first three of these statements work. The fourth doesn't.

String::Format( "{0}{0}{0}{ 0}", S"");
String::Format( "{0}{1}{0}{ 0}", S"", S"");
String::Format( "{0}{1}{2}{ 0}", S"", S"", S"");
String::Format( "{0}{1}{2}{ 3}", S"", S"", S"", S"");

Question #1: Why?
Because only the first 3 overloads are declared and defined.

Perhaps you meant to ask why that decision was made. The
threshold had to be established somewhere. Where it is set
now seems reasonable but to know for sure whether it is
optimal would require looking at a lot of code and making
an arbitrary decision about the code space versus execution
time tradeoff.
Question #2: What is the simplest way to get this to work. I would prefer to keep this statement on one line as opposed to
separate statements to declare, populate, and use a parameter array variable.


Your dispreferred method is the only way if you insist on a
single call to String::Format( ). If you love "single line" enough,
you can concatenate the results of some calls that observe the
3 parameter limitation. Personally, I would consider that to
be honoring a fetish rather than having any real merit.

--
--Larry Brasfield
email: do************* **********@hotm ail.com
Above views may belong only to me.
Nov 17 '05 #2
Larry Brasfield wrote:
Your dispreferred method is the only way if you insist on a
single call to String::Format( ). If you love "single line" enough,
you can concatenate the results of some calls that observe the
3 parameter limitation. Personally, I would consider that to
be honoring a fetish rather than having any real merit.


It would be nice if this just worked; after all C has had sprintf and
varargs support for ages. But you are right; this isn't a huge deal by
itself and is fairly easily worked around. The variety of MC++ bugs and
issues that I've had to deal with in the last 24 hours have just made me
a little inpatient.
Nov 17 '05 #3
"Tommy Vercetti" <ve*********@ho tmail.com> wrote in message
news:ut******** ******@TK2MSFTN GP12.phx.gbl...
It would be nice if this just worked; after all C has had sprintf and
varargs support for ages. But you are right; this isn't a huge deal by
itself and is fairly easily worked around. The variety of MC++ bugs and
issues that I've had to deal with in the last 24 hours have just made me a
little inpatient.


It just works in VC++ 2005 when using the new C++/CLI syntax.

-cd
Nov 17 '05 #4
On Thu, 17 Feb 2005 16:20:44 -0600, Tommy Vercetti
<ve*********@ho tmail.com> wrote:
Larry Brasfield wrote:
Your dispreferred method is the only way if you insist on a
single call to String::Format( ). If you love "single line" enough,
you can concatenate the results of some calls that observe the
3 parameter limitation. Personally, I would consider that to
be honoring a fetish rather than having any real merit.


It would be nice if this just worked; after all C has had sprintf and
varargs support for ages. But you are right; this isn't a huge deal by
itself and is fairly easily worked around. The variety of MC++ bugs and
issues that I've had to deal with in the last 24 hours have just made me
a little inpatient.


I haven't been an inpatient since my appendectomy. :)

But I do agree, I find MFC quite infuriating and much more difficult
to code and debug than regular Win32 API coding in C (and C++ where
appropriate).

--
Sev
Nov 17 '05 #5
Severian wrote:
But I do agree, I find MFC quite infuriating and much more difficult
to code and debug than regular Win32 API coding in C (and C++ where
appropriate).


What has this got to do with the original poster's question, which
relates to the .NET framework API?

--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the thermal post part of my e-mail address
with "kapsch" and the top level domain part with "net".
Nov 17 '05 #6
On Fri, 18 Feb 2005 09:02:44 +0100, Gerhard Menzl
<ge***********@ hotmail.com> wrote:
Severian wrote:
But I do agree, I find MFC quite infuriating and much more difficult
to code and debug than regular Win32 API coding in C (and C++ where
appropriate).


What has this got to do with the original poster's question, which
relates to the .NET framework API?


Perhaps you missed the OP's comment in his response:

"The variety of MC++ bugs and issues that I've had to deal with in the
last 24 hours have just made me a little inpatient."

And perhaps I misread MC++ as MFC, too!

--
Sev
Nov 17 '05 #7
Tommy Vercetti wrote:
Larry Brasfield wrote:
Your dispreferred method is the only way if you insist on a
single call to String::Format( ). If you love "single line" enough,
you can concatenate the results of some calls that observe the
3 parameter limitation. Personally, I would consider that to
be honoring a fetish rather than having any real merit.
It would be nice if this just worked; after all C has had sprintf and
varargs support for ages.

Yes, the most error prone and dangerous way for string formatting!
But you are right; this isn't a huge deal by
itself and is fairly easily worked around.

Using StringBuilder may be an option for building complex strings.

Arnaud
MVP - VC
Nov 17 '05 #8

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

Similar topics

2
4050
by: san | last post by:
Hello, all! I have question about String.Format method. There are two variants: public static string Format(string, params object); and public static string Format(IFormatProvider, string, params object); What happens if i will use String.Format("{0} and {1}", "one", "two") instead of String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} and {1}", "one", "two")?
5
3898
by: raffelm | last post by:
I'm struggling to find a way to include long path names in a command line argument string that I have to build at runtime. I need to create a string like -o:"c:\my documents\my file.txt". Everything I have tried so far causes the program I am calling to fail (I know it can accept long file names as I have tried it from the cmdline). The problem I am having is using the Format command and getting "
2
36890
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double val = { 1.0, 2.0, 3.0, 4.0 }; string fmt = "{0} {1} {2} {3}"; The following variations of string.Format() will work just fine with strings: string s1 = String.Format(fmt, str, str, str, str); // works
7
6501
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me where I can look up explaination on the String.Format, the format string part like "("{0:.#0}". What's the trailing 0 and what is that "0:" means? I assume the "#" is the place holder character for th value obtain after the comma in the code. ...
6
5247
by: Scewbedew | last post by:
Suppose I have the following code: string myFormat = "Line1/nLine 2"; string formattedString = string.Format(myFormat); ....that would produce a 2-line output as expected. But if I load that very same format string from an xml file: ....load xmlNode WorkNode...
8
4996
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to string and print it. but i want to use the String.Format() method if possible to do it.
1
10703
by: Remi THOMAS | last post by:
Hi, When you execute this line of code string script = string.Format("foreach (GroupDoc gdoc in {0}.SetGroup(\"{1}\") {\r\n", "p1", "p2"); You get System.FormatException was unhandled Message="Input string was not in a correct format." Source="mscorlib"
15
2620
by: James | last post by:
Which is better, which is faster, which is easier etc... ????? String.Format ( "yadda {0} yadda {1}", x, y ) "yadda" + x.ToString() + " yadda" + y.tostring(); My code has a mish mash of both and I am wondewring if I should standardize or not ??
8
2231
by: Armando Rocha | last post by:
Hi, Hi have a string with 16 chars "25DD68EDEB8D5E11" and i want show it in form like this "25DD-68ED-EB8D-5E11", i try String.Format("{0:####-####-####-####}", mystr), but not work, i think that it is because the "mystr" it is already a string. Anyone can help me? Sorry my english....
0
11148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10419
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9577
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7974
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7133
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4618
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3236
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.