[英]Is there a easy way to have a substring of a utf8 encode string, the substring's repr's length less than N in python
例如我有一个字符串,我希望找到一种简单的方法来获取以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
谢谢!
可能的方法:
'
或"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.