Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2010, 05:43 PM   #1 (permalink)
Registered Member
 
K2mia's Avatar
 
Join Date: Jun 2010
Posts: 29
K2mia is on a distinguished road
Default Can someone please show me ....

an example of how to parse a string and globally replace occurrences of strings matching a pattern?

I come from a Perl background and what I want to be able to do with an iphone app is to parse Ansi color codes from a text string to create a string with the colors specified via html font tags.

Here is a quick Perl example which substitutes the yellow escape code ( \e[31m ) for the yellow font tag inside the string $string

Code:
$yellow_start = "<font color='yellow'>";                                       #line1
$yellow_end = "</font>";                                                           #line2
$string = "\e[31mYellow\e[0m";                                                   #line3
$string =~ s/\e\[31m(Yellow)\e\[0m/$yellow_start$1$yellow_end/g;  #line4
I can do that easily enough in Perl but I am clueless about how to go about the string substitution in ObjC.

Can anybody provide me a quick example for the above? I would be most appreciative!

Thank you,
Andy
K2mia is offline   Reply With Quote
Old 07-07-2010, 06:31 PM   #2 (permalink)
Crafty Veteran
 
Magic Hands's Avatar
 
Join Date: Nov 2008
Location: Memphis, TN
Age: 23
Posts: 436
Magic Hands is on a distinguished road
Send a message via Skype™ to Magic Hands
Default

This may help:
– stringByReplacingOccurrencesOfString:withString:

But I would suggest looking at NSString reference, it is extremely powerful and you may find what you are looking for there.

Hope this helps,
Magic
Magic Hands is offline   Reply With Quote
Old 07-08-2010, 06:42 AM   #3 (permalink)
Registered Member
 
K2mia's Avatar
 
Join Date: Jun 2010
Posts: 29
K2mia is on a distinguished road
Default

Thanks, that looks like it'll work for this, appreciate the help!

-Andy
K2mia is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 345
14 members and 331 guests
akacaj, c2matrix, cgokey, esoteric, EXOPTENDAELAX, GHuebner, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Sonuye857, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,652
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Sonuye857
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:20 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0