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 04-16-2011, 07:57 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 12
wassupdoc is on a distinguished road
Default Getting specific part of string

I am loading images from the iphone camera roll and I need to get the specific image number of each. I have been able to get the path to each asset as follows:
assets-library://asset/asset.JPG?id=1000000035&ext=JPG

Now how would i get just the id number and strip out the leading 1s and 0s. I am assuming as my photo collection grows that id may contain 3 or 4 useful digits, so I want to make sure I remove only the 0s.

Thanks for the help
__________________
developer of:
Teleport for Dropbox - Easily upload photos and documents to Dropbox
Rhythmic - Free Sharing of your Favorite Song Info
Lytes - causes, symptoms, diagnosis, and treatment of electrolyte disorders.
Acid Plus - interpret acid-base results from ABGs and metabolic panels
wassupdoc is offline   Reply With Quote
Old 04-16-2011, 09:03 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by wassupdoc View Post
I am loading images from the iphone camera roll and I need to get the specific image number of each. I have been able to get the path to each asset as follows:
assets-library://asset/asset.JPG?id=1000000035&ext=JPG

Now how would i get just the id number and strip out the leading 1s and 0s. I am assuming as my photo collection grows that id may contain 3 or 4 useful digits, so I want to make sure I remove only the 0s.

Thanks for the help
NSString has a bunch of useful methods for string parsing.

rangeOfString: is where you should start.

If your path is in a string pathString, you could use code like this:

NSRange idRange = [pathString rangeOfString: @"id="];


Then you could write a while loop that skipped past a beginning "1" and some number of leading zeros.

Then you would need to calculate a range that started just after the first non-zero digit and went to the end of the string, and search the string for an "&" using rangeOfStringptions:range:locale: (That method lets you pass in a range to search inside the string. Pass zero for options, and nil for locale, since you don't need those features.) You could then calculate the range for just the digits you want, and use substringWithRange to extract the digits you want.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 04-16-2011, 11:36 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 12
wassupdoc is on a distinguished road
Default

Thanks Duncan!

I did some more searching after posting the question and found this:
Dimitris Doukas . Dev Blog Blog Archive Get values from parameters in an NSURL string - software development notebook

This worked perfectly to get me the id
Then using the returned string I used the following to get the int I needed

Code:
NSString *imageID = [parser valueForVariable:@"id"];
    NSString *newStr = [imageID substringFromIndex:2];
        int imageIDInt = [newStr intValue];
Quote:
Originally Posted by Duncan C View Post
NSString has a bunch of useful methods for string parsing.

rangeOfString: is where you should start.

If your path is in a string pathString, you could use code like this:

NSRange idRange = [pathString rangeOfString: @"id="];


Then you could write a while loop that skipped past a beginning "1" and some number of leading zeros.

Then you would need to calculate a range that started just after the first non-zero digit and went to the end of the string, and search the string for an "&" using rangeOfStringptions:range:locale: (That method lets you pass in a range to search inside the string. Pass zero for options, and nil for locale, since you don't need those features.) You could then calculate the range for just the digits you want, and use substringWithRange to extract the digits you want.
__________________
developer of:
Teleport for Dropbox - Easily upload photos and documents to Dropbox
Rhythmic - Free Sharing of your Favorite Song Info
Lytes - causes, symptoms, diagnosis, and treatment of electrolyte disorders.
Acid Plus - interpret acid-base results from ABGs and metabolic panels
wassupdoc is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nsstring, nsurl, string conversion, url

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: 362
14 members and 348 guests
dansparrow, dre, ilmman, LezB44, lorrettaui53, Nobbsy, Objective Zero, oztemel, pbart, samdanielblr, shagor012, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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