Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
utf-8字符裁剪
function slice_utf8str(str, maxLen) {
var len = str.length
var _len = 0
var i = 0
for (; i < len; i++) {
_len += str.charCodeAt(i) < 256 ? 1 : 2
if (_len > maxLen) break
}
return str.slice(0, i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.