Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting string starting with expression and case-insensitive

In my iPhone app I'm actually detecting text/html content type before showing data in an UIWebView or UITextView.

I detect this with a ContentType variable starting with "text/html", full variable looks like "text/html; charset=utf-8".

So for the moment I use this :

if (myContentType hasPrefix:@"text/html")

This is fine, but case-sensitive !

So when I have a "TEXT/HTML" content type, that doesn't work.

Is there a way to have the "hasPrefix" method getting case-insensitive ?

Thanks in advance :)

like image 435
Dough Avatar asked Jul 01 '10 08:07

Dough


1 Answers

You can use rangeOfString:options: function:

NSRange range = [myContentType rangeOfString:@"text/html" options: NSCaseInsensitiveSearch| NSAnchoredSearch];
if (range.location != NSNotFound)
     ...
like image 67
Vladimir Avatar answered Oct 28 '22 08:10

Vladimir