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

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.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-02-2010, 11:47 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 7
Default Number to word help with chars

I'm working on a project that turns numbers to words as a training exp. But I'm facing a problem, I'm using a method to collect first 3 chars as shown bellow:
Code:
NSString *a=[[NSString alloc]initWithFormat:@"%d",[snumber characterAtIndex:(0,3)]];
	
	int millions  = (int)a; 
	
	NSString *s=[[NSString alloc]initWithFormat:@"%d",[snumber characterAtIndex:(3,6)]];
	int hundredThousands = (int)s; 
	
	NSString *d=[[NSString alloc]initWithFormat:@"%d",[snumber characterAtIndex:(6,9)]];
	int thousands = (int)d;
but I keep getting the out of range error below:
Code:
2010-09-02 19:29:20.773 convert[412:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString characterAtIndex:]: Range or index out of bounds'
and the throws.
abdeir1 is offline   Reply With Quote
Old 09-02-2010, 12:10 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 635
Default

well the error means that sometimes when you access those characters, u go too far and they dont exist. Im assuming this is because sometimes you get a number like 5, and there is no thousands place, and so the app crashes. Just add in a check to see if that character exists bfor u set it and ull b fine.
kapps11 is offline   Reply With Quote
Old 09-02-2010, 12:18 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 7
Default

Tried that, I even gave a string with all 10 numbers. I'm thinking of turning it to int, using a number formatter on it, and then return it to a string, but as I said before I gave it a string in that format, could it be that characterAtIndex can only deal with one index?

Last edited by abdeir1; 09-02-2010 at 12:28 PM.
abdeir1 is offline   Reply With Quote
Old 09-02-2010, 01:12 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 7
Default

Solved turned out an int has a smaller range than I thought.
abdeir1 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: 348
20 members and 328 guests
ADY, Alsahir, Dani77, e2applets, JasonR, keeshux, linkmx, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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