teix
teix

Reputation: 61

Remove link in NSString

I want to delete a part of my NSString. I have this one : @"Test Hello http://www.google.fr wolrd" And I want to have in output : @"Test Hello other world"

Some ideas? Thx :)

Upvotes: 1

Views: 377

Answers (2)

Kevin Low
Kevin Low

Reputation: 2682

You can use NSDataDetector to search the string for any links (per Apple's formulas of course).

NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];

Then you can use stringByReplacingMatchesInString:options:range:withTemplate: to replace all the links with an empty string.

Upvotes: 2

KishoreK
KishoreK

Reputation: 962

You could use RegexKitLite like regex library to filter any URL from the string using methods like stringByReplacingOccurrencesOfRegex.

Upvotes: 0

Related Questions