• 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: NSString newbie question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString newbie question


  • Subject: Re: NSString newbie question
  • From: Craig Altenburg <email@hidden>
  • Date: Wed, 15 Mar 2006 12:46:48 -0500


On 15 Mar 2006, at 11:07 AM, Bobby B wrote:

I'm trying to do something similar w/ ObcJ/Cocoa, and I've come up with this:


NSString * myStr = @"Rating: (";
NSString * myStr1 = [myStr stringByAppendingString:[ratingOutlet stringValue]];
NSString * myStr2 = [myStr1 stringByAppendingString:@"/10)"];


[ratingTextOutlet setStringValue:myStr2];

It seems that the only way I can get what I want is to declare a new
nsstring variable each time I need to append something.


You don't have to declare new variables.  You could re-use the same
variable like:

NSString * myStr = @"Rating: (";

myStr = [ myStr stringByAppendingString: [ ratingOutlet stringValue ] ];
myStr = [ myStr stringByAppendingString . . .

This works fine because the intermediate strings are autoreleased.



You could also use formatted strings to do this:

NSString * myStr = [ NSString stringWithFormat: @"Rating(%@/10)", ratingOutlet ];


Much clearer in my opinion.

--
craig


_______________________________________________ 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: 
 >NSString newbie question (From: "Bobby B" <email@hidden>)

  • Prev by Date: Re: NSPredicate with CoreData SQL store behavior
  • Next by Date: Re: Stats libraries
  • Previous by thread: Re: NSString newbie question
  • Next by thread: Disabling the Table Panel
  • Index(es):
    • Date
    • Thread