开发者

Detecting string starting with expression and case-insensitive

开发者 https://www.devze.com 2023-01-05 04:00 出处:网络
In my iPhone app I\'m actually detecting text/html content type before showing data in an UIWebView or UITextView.

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 hasPrefi开发者_高级运维x:@"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 :)


You can use rangeOfString:options: function:

NSRange range = [myContentType rangeOfString:@"text/html" options: NSCaseInsensitiveSearch| NSAnchoredSearch];
if (range.location != NSNotFound)
     ...


Since you are dealing with relative small strings, a quick method could be to convert myContentType to lower case before doing the comparison.

0

精彩评论

暂无评论...
验证码 换一张
取 消