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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 06-01-2009, 12:59 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 15
Exclamation Extract words from a string

Hi i have a string...
"<+37.33168900,-122.03073100>+/-100.00 bla bla"

how can i extract +37.33168900 and put it into a variable, take -122.03073100 and put this into a second variable and so on??

please help me
mercury841 is offline   Reply With Quote
Old 06-01-2009, 01:35 PM   #2 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 679
Default

is there always going to be 8 decimal places after the initial number...

ex.
121.########
orange gold is offline   Reply With Quote
Old 06-01-2009, 03:12 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 15
Default

Quote:
Originally Posted by orange gold View Post
is there always going to be 8 decimal places after the initial number...

ex.
121.########
yes. i need to separate this string in several variables.
how can i do it?
mercury841 is offline   Reply With Quote
Old 06-01-2009, 03:49 PM   #4 (permalink)
Registered Member
 
mnemonic_fx's Avatar
 
Join Date: Jun 2008
Posts: 419
Default

This might works for you.

Code:
NSRange range = [theString rangeOfString:@">"];

NSString *coordinate = [theString substringWithRange:NSMakeRange(1, range.location-1)];

NSArray *coordinateValues = [coordinate componentsSeparatedByString:@","];

NSString *xValue = [coordinateValues objectAtIndex:0];
NSString *yValue = [coordinateValues objectAtIndex:1];
__________________
Visit Me

Writing code is not only about writing instructions to a machine / computer, but also about writing something that could be read, understood, and maintained by others. That's why, I like Cocoa.
mnemonic_fx is offline   Reply With Quote
Old 06-01-2009, 04:57 PM   #5 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Unless you're 100% sure the string format will never change, you might want to investigate using a regular expression library to parse the values out. I've been using RegExKit Lite for this with great success.
jsd is offline   Reply With Quote
Old 03-04-2011, 06:06 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Hellas
Posts: 3
Default

Quote:
Originally Posted by mnemonic_fx View Post
This might works for you.

Code:
NSRange range = [theString rangeOfString:@">"];

NSString *coordinate = [theString substringWithRange:NSMakeRange(1, range.location-1)];

NSArray *coordinateValues = [coordinate componentsSeparatedByString:@","];

NSString *xValue = [coordinateValues objectAtIndex:0];
NSString *yValue = [coordinateValues objectAtIndex:1];

Excellent! Thanks
apost is offline   Reply With Quote
Reply

Bookmarks

Tags
string, variable

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
» Stats
Members: 158,761
Threads: 89,201
Posts: 380,570
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jam3skn0
Powered by vBadvanced CMPS v3.1.0

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