Skip to content

Instantly share code, notes, and snippets.

@drnikki
Created June 20, 2012 15:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save drnikki/2960578 to your computer and use it in GitHub Desktop.
Handy function to parse kanji out of sentences
function parseText(text) {
// simplified version of this guys' http://buildingonmud.blogspot.com/2009/06/convert-string-to-unicode-in-javascript.html
var charArray = text.split('');
var justKanji = [];
charArray.forEach( function(item) {
// rejection ranges found @unicodemap.com
// http://www.unicodemap.org/range/62/Hiragana/ & http://www.unicodemap.org/range/63/Katakana/
// 12352 - 12543
var unicode = item.charCodeAt(0);
console.log(unicode);
if (unicode < 12352 || unicode > 12543) {
justKanji.push(item);
}
});
return justKanji;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment