tooltipHtml - 从谷歌地图调用中提取

发布于 2024-11-13 00:19:18 字数 149 浏览 3 评论 0原文

“ (2.1\x26#160;mi / 7 分钟)”

我有上面的字符串,我只需要获取距离和时间。我将如何使用 RegexKitLite 脚本来执行此操作?理想情况下,以下是我正在寻找的:

时间 = 7 分钟 距离 = 2.1 英里

谢谢

" (2.1\x26#160;mi / 7 mins)"

I have the above string and I need to get to the distance and time only. How would I go about doing this using the RegexKitLite script? Ideally, the below is what I'm looking for:

time = 7 mins
distance = 2.1 miles

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花桑 2024-11-20 00:19:18

不使用 RegexKitLite 脚本,但我这样做了:

NSString* tooltipHtml = [apiResponse stringByMatching:@"tooltipHtml:\\"([^\\"]*)\\"" capture:1L];

NSLog(@"tooltip Html: %@", tooltipHtml);


int leftParanthesis = [tooltipHtml rangeOfString:@"("].location;
int inverseSlash = [tooltipHtml rangeOfString:@"\\"].location;
int slash = [tooltipHtml rangeOfString:@"/"].location;
int semiColumn = [tooltipHtml rangeOfString:@";"].location;
int rightParanthesis = [tooltipHtml rangeOfString:@")"].location;


NSRange distanceRange = NSMakeRange(leftParanthesis+1, inverseSlash-leftParanthesis-1);
NSString *distance = [tooltipHtml substringWithRange:distanceRange];

NSRange distanceTypeRange = NSMakeRange(semiColumn+1, slash-semiColumn-1);
NSString *distanceType = [tooltipHtml substringWithRange:distanceTypeRange];

NSRange timeRange = NSMakeRange(slash+1, rightParanthesis-slash-1);
NSString *time = [tooltipHtml substringWithRange:timeRange];
NSString *distanceCompact = [distance stringByAppendingString:distanceType];

NSLog(@"Distance %@:", distance);
NSLog(@"Distance type %@:", distanceType);
NSLog(@"Time %@:", time);
NSLog(@"distance Compact %@:", distanceCompact);

Not with RegexKitLite script but I've done it this way:

NSString* tooltipHtml = [apiResponse stringByMatching:@"tooltipHtml:\\"([^\\"]*)\\"" capture:1L];

NSLog(@"tooltip Html: %@", tooltipHtml);


int leftParanthesis = [tooltipHtml rangeOfString:@"("].location;
int inverseSlash = [tooltipHtml rangeOfString:@"\\"].location;
int slash = [tooltipHtml rangeOfString:@"/"].location;
int semiColumn = [tooltipHtml rangeOfString:@";"].location;
int rightParanthesis = [tooltipHtml rangeOfString:@")"].location;


NSRange distanceRange = NSMakeRange(leftParanthesis+1, inverseSlash-leftParanthesis-1);
NSString *distance = [tooltipHtml substringWithRange:distanceRange];

NSRange distanceTypeRange = NSMakeRange(semiColumn+1, slash-semiColumn-1);
NSString *distanceType = [tooltipHtml substringWithRange:distanceTypeRange];

NSRange timeRange = NSMakeRange(slash+1, rightParanthesis-slash-1);
NSString *time = [tooltipHtml substringWithRange:timeRange];
NSString *distanceCompact = [distance stringByAppendingString:distanceType];

NSLog(@"Distance %@:", distance);
NSLog(@"Distance type %@:", distanceType);
NSLog(@"Time %@:", time);
NSLog(@"distance Compact %@:", distanceCompact);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文