gpt4 book ai didi

ios - 如何解析 NSString

转载 作者:行者123 更新时间:2023-11-28 18:09:10 25 4
gpt4 key购买 nike

字符串是 myAgent(9953593875).Amt:Rs.594 并想从中提取 9953593875。这是我尝试过的:

NSRange range  =  [feDetails rangeOfString:@"."];
NSString *truncatedFeDetails = [feDetails substringWithRange:NSMakeRange(0, range.location)];
NSLog(@"truncatedString-->%@",truncatedFeDetails);

输出:truncatedString-->AmzAgent(9953593875)

最佳答案

或者你这样做:

NSString *string = @"myAgent(9953593875).Amt:Rs.594.";

NSRange rangeOne = [string rangeOfString:@"("];
NSRange rangeTwo = [string rangeOfString:@")"];

if (rangeOne.location != NSNotFound && rangeTwo.location != NSNotFound) {
NSString *truncatedFeDetails = [string substringWithRange:NSMakeRange(rangeOne.location + 1, rangeTwo.location - rangeOne.location - 1)];
NSLog(@"%@",truncatedFeDetails);

}

关于ios - 如何解析 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36832656/

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