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.

2

2 Answers 2

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:@""];
Sign up to request clarification or add additional context in comments.

Comments

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)];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.