Created
August 1, 2017 03:55
-
-
Save MJ111/47caea5f4bc2baf6e4213041c2d48e20 to your computer and use it in GitHub Desktop.
[Remove divided surrogate pair unicode] #JavaScript #Unicode
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
| /* | |
| * This would be necessary If you have limited length textarea and sliced the input string. | |
| * because individual surrogate codes are useless and raise error in Python and broken character is ugly | |
| * (https://unicode-table.com/en/blocks/high-surrogates/) | |
| */ | |
| function SliceAndCleanInputStr (inputStr) { // inputStr = 'aaaaaa😄' | |
| var sliced = inputStrstr.slice(0, 7) // "aaaaaa�" | |
| return sliced.replace(/[\ud800-\udbff]/g, '') // "aaaaaa" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment