Finding http-links in NSString
Had some problem with long http links in a UIWebView so I created this simple function that finds links existing in a NSString and creates an a-tag with a “Read more” label. Suited my needs for the moment.
- (NSString *)parseLinks:(NSString *)html { NSScanner *theScanner; NSString *text = nil; theScanner = [NSScanner scannerWithString:html]; while ([theScanner isAtEnd] == NO) { // find start of tag [theScanner scanUpToString:@"http" intoString:NULL] ; // find end of tags [theScanner scanUpToString:@"<" intoString:&text] ; html = [html stringByReplacingOccurrencesOfString: [NSString stringWithFormat:@"%@", text] withString:[NSString stringWithFormat:@"Read more", text]]; break; } return html; }
Finding http-links in NSString
Had some problem with long http links in a UIWebView so I created this simple function that finds links existing in a NSString and creates an a-tag with a “Read more” label. Suited my needs for the moment.
- (NSString *)parseLinks:(NSString *)html { NSScanner *theScanner; NSString *text = nil; theScanner = [NSScanner scannerWithString:html]; while ([theScanner isAtEnd] == NO) { // find start of tag [theScanner scanUpToString:@"http" intoString:NULL] ; // find end of tags [theScanner scanUpToString:@"<" intoString:&text] ; html = [html stringByReplacingOccurrencesOfString: [NSString stringWithFormat:@"%@", text] withString:[NSString stringWithFormat:@"Read more", text]]; break; } return html; }
Posted 2 years ago