Created
September 1, 2010 08:01
-
-
Save brianhsu/560384 to your computer and use it in GitHub Desktop.
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
| val content = "我是陶喆\n我是游鍚堃\n這是測試" | |
| println (normalizeString(content)) | |
| def normalizeString (string: String) = string.flatMap(escapeNonBig5Character _) | |
| def escapeNonBig5Character (character: Char): String = { | |
| def isNotBig5 (character: Char) = character.toString.getBytes("Big5")(0) == '?' && | |
| character != '?' | |
| isNotBig5(character) match { | |
| case true => "&#%d;" format(character.toInt) // 不是 Big5 的字元就轉成字元參引 | |
| case false => character.toString // 不然的話維持原樣 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment