2011-05-31 36 views
0

“(2.1 \ x26#160; mi/7分钟)”tooltipHtml - 谷歌地图提取

我有上面的字符串,我只需要到达距离和时间只。我将如何使用RegexKitLite脚本来做这件事?理想情况下,下面就是我在寻找:

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

感谢

回答

0

不与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);