Created
August 10, 2018 01:33
-
-
Save davidleee/27454c92c6bb5fb28c551756de4510f0 to your computer and use it in GitHub Desktop.
An extension for String to detect if it contains Chinese characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
var containsChinese: Bool { | |
for substring in self { | |
if substring.isChinese { | |
return true | |
} | |
} | |
return false | |
} | |
} | |
extension Character { | |
var isChinese: Bool { | |
if ("\u{4E00}" <= self && self <= "\u{9FA5}") { | |
return true | |
} else { | |
return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment