On Jan 22, 2011, at 9:37 AM, cocoa-dev-requ...@lists.apple.com wrote: > Date: Sat, 22 Jan 2011 09:19:50 -0500 > From: Jeremy Matthews <jeremymatth...@mac.com> > Subject: lots of find/replace in text file > > So...the app I previously mentioned, ala Mad Libs...I now have lots more text > to replace within the file (new additions). Besides using find/replace using > NSScanner and NSStrings' stringByReplacingOccurrencesOfString....is there a > better way, to perform a slew of find/place operations with a text file? > > So far, I have an array of strings (placeholders) which get replaced by an > array of user-determined values, and the resulting mishmash gets spewed into > a file. > > I can't help but think there might be a better (and more efficient way) of > handling this?
What is mean by "better" or "efficient"? What is inefficient about what you're doing? Have you actually done any Instruments testing or are you just guess what's efficient and what's not? I do have some other suggestions but I don't necessarily mean there is anything more "efficient" about them: (1) We now have regular expressions and blocks. (2) A common trick is make the text file a format string (i.e., containing a lot of %@) and just hand it to stringWithFormat along with all the substitutions. Badda bing badda boom. m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ pantes anthropoi tou eidenai oregontai phusei Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf AppleScript: the Definitive Guide, 2nd edition http://www.tidbits.com/matt/default.html#applescriptthings Take Control of Exploring & Customizing Snow Leopard http://tinyurl.com/kufyy8 RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com