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

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

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, 11:59 AM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 8
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, 12:35 PM   #2 (permalink)
Gold Orange
 
orange gold's Avatar
 
Join Date: Sep 2008
Posts: 572
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, 02:12 PM   #3 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 8
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, 02: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, 03:57 PM   #5 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 871
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
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
» Online Users: 366
21 members and 345 guests
AdamSubach, anonymous@, benoitr007, bensj, Duncan C, gtyt38, Jeremy1026, lifeCoder45, maxus182, mox, Mr. Mojo Risin, Ovidius, Paul10, pofak, raheel, squidboy, ufbobbo, ultrayard077
Most users ever online was 965, 06-30-2010 at 04:26 AM.
» Stats
Members: 41,859
Threads: 49,768
Posts: 213,052
Top Poster: BrianSlick (3,138)
Welcome to our newest member, ultrayard077
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0