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

Re: Fairly newbie question on strings


  • Subject: Re: Fairly newbie question on strings
  • From: Joshua Scott Emmons <email@hidden>
  • Date: Thu, 26 Jan 2006 19:05:40 -0600

So I need to get the first bit of string: "Today is "
Add on to it nameOfToday
And then append on to that "."

What would be the best way of achieving this? I am looking at stringWithFormat of NSString. Would this be the best choice?

I guess it depends on if you're after readability or efficiency. If readability is the issue then I think it'd be hard to beat:


[NSString stringWithFormat:@"Today is %@.", nameOfToday];

Your alternative is to do something like:

[[@"Today is" stringByAppendingString:nameOfToday] stringByAppendingString:@"."];

And that's just ugly.

If your concern is efficiency, there's probably some trick dealing with NSMutableString that would be able to do all this for you in fewer cycles. But for all the time it would save you, I'd rather go with the simple and readable -stringWithFormat: any day.


Cheers, -Joshua Emmons

_______________________________________________
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


  • Follow-Ups:
    • Re: Fairly newbie question on strings
      • From: Douglas Davidson <email@hidden>
References: 
 >Fairly newbie question on strings (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: I think I have found a big bug in NSBrowser
  • Next by Date: Re: Fairly newbie question on strings
  • Previous by thread: Fairly newbie question on strings
  • Next by thread: Re: Fairly newbie question on strings
  • Index(es):
    • Date
    • Thread