2011-05-31 71 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);