Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wesg

macrumors regular
Original poster
Jan 2, 2008
211
0
Toronto, ON
I'm just getting started in the world of Cocoa and Obj C and I'm stuck on a component. Aaron Hillegrass' book is helping me through, but my app keeps breaking. I learned C at university, and dabble with other languages here and there, so that helps, but the problem I'm having right now is comparing the first character of 2 strings. I think it has to do with the data types.

What my goal for this piece of code, is to take a number (06 or 10, for example) and remove the leading zero if it has one. Maybe I'm missing a simple function, but here's what I have so far.

Code:
fileseason = @"06";
firstchars = [NSString stringWithFormat:@"%d", [fileeason substringToIndex:1]];

if (firstchars == 0)
fileseason = [fileeason substringFromIndex:1];
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
If you want to remove the leading zeros off an integer then

Code:
NSString *newString=[NSString stringWithFormat:@"%d",[oldString intValue]];

will work...
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
eraserhead provided a solution, but I thought for future reference I'd cover what the OP had asked.
-characterAtIndex provides a unichar which could be compared using == to another unichar to check against a particular value.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.