例如我有一个字符串,我希望找到一个简单的方法来获取一个子字符串,其编码在utf-8中,并且子字符串的repr的长度是< = N,当然我可以尝试N / 3个子串并增加N / 3 + 1,N / 3 + 2,...,但是如果有一个简单的方法呢?
word = u"this is a ship, and some other words".encode("utf-8")
#some way got a substring
substring = func(word, N)
#assert len(repr(substring)) <= N
谢谢!
答案 0 :(得分:1)
可能的方法:
'
或"
。