gpt4 book ai didi

iphone - NSString-2位数字

转载 作者:行者123 更新时间:2023-12-01 19:27:34 25 4
gpt4 key购买 nike

嗨,
我有一个带有2位数字的字符串(如32),但我想获取并使用它作为2位数字(例如3和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"]) {
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];

它现在可以与数字(即32)一起使用,但是如果我尝试只输入一个数字,我会得到一个错误....知道吗?谢谢

最佳答案

循环遍历并一次从字符串中提取一个字符。

for(int i = 0; i < [myString length]; i++)
{
char extractedChar = [myString characterAtIndex:i];

if(extractedChar == '1')....
}

关于iphone - NSString-2位数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5994259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com