gpt4 book ai didi

ios - 修剪 NSString

转载 作者:行者123 更新时间:2023-11-29 04:08:39 25 4
gpt4 key购买 nike

我正在按以下方式修剪 NSString:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"X = (\\d+.\\d+), Y = (\\d+.\\d+), (%@)" options:0 error:NULL];
NSTextCheckingResult *match = [regex firstMatchInString:txt.text options:0 range:NSMakeRange(0, [txt.text length])];
if (match) {
NSRange firstHalfRange = [match rangeAtIndex:1];
NSString *xString = [txt.text substringWithRange:firstHalfRange];
NSRange secondHalfRange = [match rangeAtIndex:2];
NSString *yString = [txt.text substringWithRange:secondHalfRange];
NSRange thirdHalfRange = [match rangeAtIndex:3];
NSString *colorString = [txt.text substringWithRange:thirdHalfRange];

NSLog(@"X = %@, Y = %@, Color: %@", yString, xString, colorString);
}

NSString 看起来像这样:

@"this is the content. The content of this string may vary, as well as the length, and my include any characters, with numbers X = 295.000000, Y = 207.500000, TheWhite"

Y = 295.000000 X = 207.500000 部分始终保持不变,除了 X 和 Y 数字可能会发生变化,以及:TheWhite,它可能会变成例如黑衣

使用此方法,我成功提取了 X 和 Y 值,但没有提取最终的字符串。我做错了什么?

最佳答案

您的模式以(%@)结尾。我应该以 (.+) 结尾。

关于ios - 修剪 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14781728/

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