gpt4 book ai didi

iphone - 将 NSString 转换为 Int

转载 作者:行者123 更新时间:2023-12-03 20:51:39 26 4
gpt4 key购买 nike

我尝试将NSString转换为int,结果dpPoint:0,我想要dpPoint:2

dpPointStr = [NSString stringWithFormat:@"%@",[verifyRow valueForKey:@"default_point"]];
NSLog(@"dpPointStr:%@",dpPointStr); //Result dpPointStr:2

int dpPoint = [dpPointStr intValue];
NSLog(@"dpPoint:%i",dpPoint); //Result dpPoint:0

最佳答案

在您的情况下,如果值位于字符串的开头/结尾,您可以尝试以下操作:

int val = [[dpPointStr stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] intValue];

关于iphone - 将 NSString 转换为 Int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13802850/

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