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 01-26-2012, 11:55 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 51
Pyroclastic is on a distinguished road
Default Splitting NSString into char array

Hi, I need to split a NSString into chunks of 10 characters for an arbitrary length of a string and then store this into a char array.

I'm fairly new to C programming (about a day in) and only previously had experience in C++ and Objective-C.

For example given the string:

Code:
@"123454312437390989276346829038443"
I would like the following:

Code:
const char* chunks[] = {"1234543124", "3739098927", "6346829038", "443"};
I have had a look at the NSString functions for splitting strings, but nothing seems to do what I want. Some indication on how to achieve this would be appropriated.
Pyroclastic is offline   Reply With Quote
Old 01-26-2012, 12:28 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

probably your best bet is using a loop using either:

NSString *chunk = [str substringToIndex:10];

or
[str substringWithRange:NSMakeRange(1,10)];
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 01-26-2012, 12:47 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 51
Pyroclastic is on a distinguished road
Default

Thanks for the reply.

That would give me an index out of bounds for the last string since its only 3 chars long.

I suppose I could try and add an if statement to check the length .... hmm i'll see if it works
Pyroclastic is offline   Reply With Quote
Old 01-27-2012, 10:49 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 51
Pyroclastic is on a distinguished road
Default

Working now thanks, just need two for loops and a little know how to do what I wanted
Pyroclastic 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: 404
9 members and 395 guests
Atatator, condor304, FrankWeller, MAMN84, mraalex, n00b, PowerGoofy, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

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