Skip to content

Instantly share code, notes, and snippets.

@wrdso
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrdso/902482c847e4f20b53e5 to your computer and use it in GitHub Desktop.
Save wrdso/902482c847e4f20b53e5 to your computer and use it in GitHub Desktop.
Calculate full-width CJK char string length (utf8)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
string = "貓" #cat
s_utf8 = string.decode('utf8')
print len(s_utf8) #output = 1
string_2 = "狗!" #dog!
s_utf8_2 = string_2.decode('utf8')
print len(s_utf8_2) #output = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment