• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stringWithFormat: problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringWithFormat: problem


  • Subject: Re: stringWithFormat: problem
  • From: Keith Wilson <email@hidden>
  • Date: Sun, 5 Feb 2006 00:30:56 +1100

Sorry, you will need to replace

NSString *pString = [NSString stringWithFormat:format arguments:argPtr];
with


NSString *pString = [[[NSString alloc] initWithFormat:format arguments:argPtr] autorelease];


and also the first example should have been

	DisplayMessage(@"This is %@ formatted string of %@", @"a", @"mine");

Keith

On 05/02/2006, at 12:22 AM, Keith Wilson wrote:

I'm not sure what your intended purpose is, but maybe you want a general utility using va_list, something like
the following:


// ********************************************************************** *******
void DisplayMessage(NSString* format, ...)
{
va_list argPtr;
va_start (argPtr, format);
NSString *pString = [NSString stringWithFormat:format arguments:argPtr];
va_end(argPtr);
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:pString];
[alert runModal];
[alert release];
}
// ********************************************************************** *******
then you could call


DisplayMessage(@"This is %@ formatted string of mine", @"a", @"mine");

or maybe

DisplayMessage("At line %ld in method %@ the value of floatVar was %6.3f ", __LINE__, @"readTheFile", floatVar);


Keith

On 04/02/2006, at 10:18 PM, Thierry Passeron wrote:

Well, I should have been more specific, so ...

Of course Markus, I do the checking of [theArray count] along with an NSScann...ing of the format string to check if there is enough elements for the format.
And the example I gave above was just as a [array description] would output.
So I do use NSStrings in the array (hence the %@) and I do check the number of elements.


Well, my question is still opened :)

Best regards,
Thierry

Le 4 févr. 06 à 11:15, Markus Hitter a écrit :


Am 04.02.2006 um 10:37 schrieb Thierry Passeron:

I have 2 objects, one is a formated string like @"This is %@ formated
string of %@".
The other is an array of string { "a", "mine" }.

This is an array of C strings, not NSStrings. To store strings in an NSArray, you have to use NSStrings. To format C strings, you have to use the %s formatter, not %@.


How is it possible to do that when you don't know what will be the
number of string in the array ?

Before you compose the resulting string, you have to check wether the ingredients exist. -[NSArray count] should help.



Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40bigpond.net.au


This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40bigpond.net.au


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >stringWithFormat: problem (From: Thierry Passeron <email@hidden>)
 >Re: stringWithFormat: problem (From: Markus Hitter <email@hidden>)
 >Re: stringWithFormat: problem (From: Thierry Passeron <email@hidden>)
 >Re: stringWithFormat: problem (From: Keith Wilson <email@hidden>)

  • Prev by Date: Re: stringWithFormat: problem
  • Next by Date: Re: creating a preference window safari style
  • Previous by thread: Re: stringWithFormat: problem
  • Next by thread: Disable cut, copy etc.
  • Index(es):
    • Date
    • Thread