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 09-20-2010, 10:31 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 32
garyshaf is on a distinguished road
Default Problem with substring from NSArray

Hi everyone,

I can't seem to figure out how to get a substring from an array element to a different string:

I have the following NSArray:

"image1.png|Description for image"
"image2.png|Description for image"
"image3.png|Description for image"

I already have the image name in a for loop but can't get the descpription where it matches the image name in the array.

Code:
NSString *imageDesc = nil;

NSString *positionsPath = [[NSBundle mainBundle]  pathForResource:@"position_descriptions" ofType:@"txt" inDirectory:@"/"];
	NSArray *positionsDesc = [[NSString stringWithContentsOfFile:positionsPath encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
	
...
...
...

UIImage *image = [UIImage imageNamed:imageName];
		imageView = [[UIImageView alloc] initWithImage:image];
I'd like to get the corresponding imageDesc from NSArray where it's equal to the imageName.

Any help would greatly be appreciated.

Thanks!
garyshaf is offline   Reply With Quote
Old 09-20-2010, 01:13 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 32
garyshaf is on a distinguished road
Default

Quote:
Originally Posted by garyshaf View Post
Hi everyone,

I can't seem to figure out how to get a substring from an array element to a different string:

I have the following NSArray:

"image1.png|Description for image"
"image2.png|Description for image"
"image3.png|Description for image"

I already have the image name in a for loop but can't get the descpription where it matches the image name in the array.

Code:
NSString *imageDesc = nil;

NSString *positionsPath = [[NSBundle mainBundle]  pathForResource:@"position_descriptions" ofType:@"txt" inDirectory:@"/"];
	NSArray *positionsDesc = [[NSString stringWithContentsOfFile:positionsPath encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
	
...
...
...

UIImage *image = [UIImage imageNamed:imageName];
		imageView = [[UIImageView alloc] initWithImage:image];
I'd like to get the corresponding imageDesc from NSArray where it's equal to the imageName.

Any help would greatly be appreciated.

Thanks!
Nevermind... figured it out.
garyshaf 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: 312
13 members and 299 guests
2ndSegment, cayladv57, cgokey, djohnson, Domele, Hamad, linkmx, markuschow, pungs, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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