MC++ String::Format?

  • Thread starter Thread starter Tommy Vercetti
  • Start date Start date
T

Tommy Vercetti

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.
 
Tommy Vercetti said:
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 said:
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.
 
Tommy Vercetti said:
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
 
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).
 
Severian said:
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".
 
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!
 
Tommy said:
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
 
Back
Top