美文网首页
如何检测字符串是否含有中文

如何检测字符串是否含有中文

作者: 淇滨杜隆坦 | 来源:发表于2016-06-18 11:20 被阅读94次

//判断是否有中文

-(BOOL)whetherHasChineseCharacter:(NSString *)str
{
           for(int i=0; i< [str length];i++)
           {
                      int a = [str characterAtIndex:i];
                      if( a > 0x4e00 && a < 0x9fff)
                      {
                                 //一旦碰到一个中文字符,立即返回
                                 return YES;
                      }
            }
           // 来到这,说明没有中文
           return NO;
}

相关文章

网友评论

      本文标题:如何检测字符串是否含有中文

      本文链接:https://www.haomeiwen.com/subject/ecavdttx.html