Skip to content

Instantly share code, notes, and snippets.

@davidleee
Created August 10, 2018 01:33
Show Gist options
  • Save davidleee/27454c92c6bb5fb28c551756de4510f0 to your computer and use it in GitHub Desktop.
Save davidleee/27454c92c6bb5fb28c551756de4510f0 to your computer and use it in GitHub Desktop.
An extension for String to detect if it contains Chinese 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