您当前的位置: 首页 >  swift

Swift如何判断字符串的语言

发布时间:2016-11-29 20:22:59 ,浏览量:0

有时我们需要判断一段文字是属于那种语言:英文?韩文?还是中文?虽说这也算某种程度的猜测,但至少比你自己瞎猜要准确地多! ;)

这里提供三种方法.

首先如果你只在MacOS上运行的话,你可以用AppKit中的NSSpellChecker类:

import AppKit

let checker = NSSpellChecker.shared()
checker.automaticallyIdentifiesLanguages = true
let str = "猫猪侯佩,弄啥呢!!!" checker.requestChecking(of: str, range: NSRange(location: 0,length: str.characters.count), types: NSTextCheckingResult.CheckingType.orthography.rawValue, options: nil, inSpellDocumentWithTag: 0){num,results,orthography,count
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    107766博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0495s