`Hi,
i have a string with a 2 digit numbers (like 32) but i want to get and use it as 2 single digit number (like 3 and 2). how can I do it? thanks in advance.
NSString *depositOverTotalRwy = [NSString stringWithFormat:@"%@", [deposit text]];
NSArray *components = [depositOverTotalRwy
componentsSeparatedByString:@"/"];
NSString *firstThird = [components objectAtIndex:0];
unichar firstChar = [firstThird characterAtIndex: 0];
NSString *firstCharStr = [NSString stringWithFormat:@"%c", firstChar];
unichar secChar = [firstThird characterAtIndex: 1];
NSString *secCharStr = [NSString stringWithFormat:@"%c",secChar];
NSLog(@"%@ over %@", firstCharStr, secCharStr);
if ([firstCharStr isEqualToString: @"1"]) {
firstCharStr=@"wet";
NSLog(@"wet");
}
if ([firstCharStr isEqualToString: @"2"]) {
firstCharStr=@"snow";
NSLog(@"snow");
}
if ([firstCharStr isEqualToString: @"3"]) {
firstCharStr=@"ice";
NSLog(@"ice");
}
if ([secCharStr isEqualToString: @"1"]) {
secCharStr=@"wet";
NSLog(@"wet");
}
if ([secCharStr isEqualToString: @"2"]) {
secCharStr=@"snow";
NSLog(@"snow");
}
if ([secCharStr isEqualToString: @"3"]) {
secCharStr=@"ice";
NSLog(@"ice");
}
NSString *secThird = [components objectAtIndex:1];
if ([secThird isEqualToString: @"1"]) {
secThird = @"wet";
NSLog(@"wet");
}
if ([secThird isEqualToString:@"2"]) {
secThird = @"snow";
NSLog(@"snow");
}
if ([secThird isEqualToString:@"3"]) {
secThird = @"ice";
NSLog(@"ice");
}
NSString *thirdThird = [components objectAtIndex:2];
if ([thirdThird isEqualToString: @"1"]) {
thirdThird = @"wet";
NSLog(@"wet");
}
if ([thirdThird isEqualToString:@"2"]) {
thirdThird = @"snow";
NSLog(@"snow");
}
if ([thirdThird isEqualToString:@"3"]) {
thirdThird = @"ice";
NSLog(@"ice");
}
dep.text = [NSString stringWithFormat:@"1/3 %@%@ 2/3 %@ 3/3 %@", firstCharStr,secCharStr, secThird, thirdThird];
it works now with to digits (ie 32) but if i try to put just one digit I get an error…. any idea? thanks
Loop through and extract one character at a time from your string.