How to have PHP Implode / Explode functions like in Obj-C ?

How to have PHP Implode / Explode functions like in Obj-C ?

Postby laurent » Sat Apr 24, 2010 9:02 am

Implode & explode functions are sometimes very usefull.
Here's the trick :

Explode like :

Supposing that you've got an NSString named "string" containing several elements separated by a pipe "|", you can get an array of each strings just like this :
Code: Select all
NSArray *myElements = [string componentsSeparatedByString: @"|"];


Implode like :

Now to get the reversed result (so have an Array of NSString and merging them into a single NSString "glued" with a separator string, do that :
Code: Select all
string = [myElements componentsJoinedByString: @"|"];


Don't forget that the glue/unglue string (the seperator) is... a string. So you also can use complex combination, not only one char.
laurent
Site Admin
 
Posts: 13
Joined: Mon Dec 29, 2008 2:35 pm

Re: How to have PHP Implode / Explode functions like in Obj-

Postby kukutt » Mon Aug 02, 2010 10:36 am

Usefull tips ! Thanks !
kukutt
 
Posts: 1
Joined: Mon Aug 02, 2010 10:33 am


Return to iPhone - Cocoa - English Tips & Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron