06-01-2009, 12:59 PM
#1 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 15
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
06-01-2009, 01:35 PM
#2 (permalink )
Gold Orange
Join Date: Sep 2008
Posts: 679
is there always going to be 8 decimal places after the initial number...
ex.
121.########
06-01-2009, 03:12 PM
#3 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 15
Quote:
Originally Posted by
orange gold
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?
06-01-2009, 03:49 PM
#4 (permalink )
Registered Member
Join Date: Jun 2008
Posts: 419
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.
06-01-2009, 04:57 PM
#5 (permalink )
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
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.
03-04-2011, 06:06 AM
#6 (permalink )
Registered Member
Join Date: Sep 2010
Location: Hellas
Posts: 3
Quote:
Originally Posted by
mnemonic_fx
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
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 623
24 members and 599 guests
Bertrand21 , BrianSlick , CS@UCSB , dschivas , Duncan C , elhanche , Gambit , GameViewPoint , hasinthajanaka , Inupgames , jeeep , leonardomota , linkmx , mistergreen2011 , Monstertaco , morgen , Oral B , PixelInteractive , Rudy , themathminister , tsai0507 , vietanh100989 , vikinara
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,761
Threads: 89,201
Posts: 380,570
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jam3skn0