안녕하세요, 저는 2 자릿수 (32와 같은)의 문자열을 가지고 있습니다. 그러나 나는 그것을 얻고 싶습니다. 3과 2 같은 2 자리 숫자로 사용하고 싶습니다. 내가 어떻게 해? 미리 감사드립니다.NSString - 2 자리 숫자
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"]) {
[email protected]"wet";
NSLog(@"wet");
}
if ([firstCharStr isEqualToString: @"2"]) {
[email protected]"snow";
NSLog(@"snow");
}
if ([firstCharStr isEqualToString: @"3"]) {
[email protected]"ice";
NSLog(@"ice");
}
if ([secCharStr isEqualToString: @"1"]) {
[email protected]"wet";
NSLog(@"wet");
}
if ([secCharStr isEqualToString: @"2"]) {
[email protected]"snow";
NSLog(@"snow");
}
if ([secCharStr isEqualToString: @"3"]) {
[email protected]"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];
이제는 숫자 (예 : 32)로 작동하지만 한 자리 만 입력하면 오류가 발생합니다 .... 어떤 생각입니까? 감사합니다
확인 문자열이 실제로 첫번째 숫자에 불과 ... [당신이 구성 요소 부분으로는 NSString 분할 어떻게, 엑스 코드를 사용]의 – bbum
가능한 중복 (포함하지 않는다 http://stackoverflow.com/questions/3942263/using-xcode-how-do-you-split-nsstring-into-component-parts) –
@ Josh Caswell 고마워, 나는 시도 할 것이다 ... – mat