1

I search this question but didn't find anything useful.

For example, I have this string:

NSString *text = @"Siguiendo la estela del <a class="colorbox" href="http://www.applesfera.com/apple/apple-presenta-un-nuevo-anuncio-del-iphone-y-vuelve-por-su-derroteros">anuncio Photos Every Day en el que la compañía de la manzana nos mostraba situaciones cotidianas para hacer hincapié en que cada día se hacen más fotos con el iPhone que con cualquier otra cámara"

And I want to eliminate, ALL content in '< >' tag, ('<''>' inclusive), so the result that I want, will be:

NSString *text = @"Siguiendo la estela del anuncio Photos Every Day en el que la compañía de la manzana nos mostraba situaciones cotidianas para hacer hincapié en que cada día se hacen más fotos con el iPhone que con cualquier otra cámara"

I see it's possible with regular expression, but I don't know how. Need guidance on what on what i could do here.

Kurt Du Bois
  • 7,550
  • 4
  • 25
  • 33
dgarcia
  • 13
  • 2
  • [This](http://stackoverflow.com/questions/2493153/search-for-a-string-between-two-known-strings) and [this](http://stackoverflow.com/questions/4002360/get-string-between-two-other-strings-in-objc) with slight modification will help you. – Anoop Vaidya May 24 '13 at 17:49
  • http://stackoverflow.com/questions/4942245/nsregularexpression-for-stripping-html-tag – CEarwood May 24 '13 at 18:48

2 Answers2

2

Have a look at this link https://stackoverflow.com/a/4886998 .I think this is what you are looking for. If you want to resue it in many place implement as specified in that post. Else simply use like this

NSRange r;
NSString *s = @"my<remove>output";
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
    s = [s stringByReplacingCharactersInRange:r withString:@""];
Community
  • 1
  • 1
George
  • 191
  • 4
0

For a simple substitution of a string, you can use stringByReplacingOccurrencesOfString:withString:options:range: like this:

NSString* result = [text stringByReplacingOccurrencesOfString: @"<.*?>"
                                                   withString: @""
                                                      options: NSRegularExpressionSearch
                                                        range: NSMakeRange(0, text.length)];
Monolo
  • 18,205
  • 17
  • 69
  • 103