• 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: Glueing strings together...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Glueing strings together...


  • Subject: Re: Glueing strings together...
  • From: j o a r <email@hidden>
  • Date: Tue, 13 Jan 2004 16:27:25 +0100

On 2004-01-13, at 16.07, Michael Becker wrote:

> I have a loop in which I need to glue strings together. Like this:
>
> for (i=0; i<[ theArray count]; i++) {
> myString = [ myString stringByAppendingFormat:"\n%@", [ theArray
> objectAtIndex:i]];
> }
>
> This works well. My only concern is memory leaking. I am creating a
> new string and setting my pointer to this new string, but does the old
> (original) string get released?
> What is the proper way to build a string out of many parts?

As long as you're working with autoreleased objects, like above, you're
fine.
In the general case you will not leak memory if you don't use copy,
alloc, new, et.c.

An alternative way to solve the problem above would be this:

NSString *myString = [myArray componentsJoinedByString: @"\n"];

j o a r

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Glueing strings together... (From: Michael Becker <email@hidden>)

  • Prev by Date: Re: Autorelease pool question
  • Next by Date: Re: Glueing strings together...
  • Previous by thread: Glueing strings together...
  • Next by thread: Re: Glueing strings together...
  • Index(es):
    • Date
    • Thread