Python实现简单截取中文字符串的方法
作者:秋风秋雨 时间:2022-09-08 01:43:48
本文实例讲述了Python实现简单截取中文字符串的方法。分享给大家供大家参考。具体如下:
web应用难免会截取字符串的需求,Python中截取英文很容易:
>>> s = 'abce'
>>> s[0:3]
'abc'
但是截取utf-8的中文机会截取一半导致一些不是乱码的乱码.其实utf8截取很简单,这里记下来作为备忘
#-*- coding:utf8 -*-
s = u'中文截取'
s.decode('utf8')[0:3].encode('utf8')
# 结果u'中文截取
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,截取,中文
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python模拟菜刀反弹shell绕过限制【推荐】
2023-07-13 12:56:18
pandas groupby 用法实例详解
2023-07-19 01:37:59
JavaScript[对象.属性]集锦
2020-07-08 18:05:45
一篇文章带你自学python Django
2023-11-13 20:33:13
![](https://img.aspxhome.com/file/2023/5/124255_0s.png)
Mysql中使用时间查询的详细图文教程
2024-01-17 16:35:54
![](https://img.aspxhome.com/file/2023/0/77210_0s.png)
Python 操作SQLite数据库的示例
2024-01-28 00:23:59
python使用matplotlib画柱状图、散点图
2023-05-18 11:50:06
![](https://img.aspxhome.com/file/2023/7/123797_0s.png)
最新版MySQL 8.0.22下载安装超详细教程(Windows 64位)
2024-01-18 15:11:02
![](https://img.aspxhome.com/file/2023/4/121584_0s.png)
图片预载ImageLoader 1.1 Release
2008-11-04 20:04:00
JDBC利用C3P0数据库连接池连接数据库
2024-01-13 12:37:51
![](https://img.aspxhome.com/file/2023/8/93148_0s.jpg)
Vue前端后端的交互方式 axios
2024-05-21 10:28:58
利用python如何在前程无忧高效投递简历
2022-10-26 22:33:02
![](https://img.aspxhome.com/file/2023/1/128511_0s.png)
javascript中实现override,overload和类似c#中的property
2008-05-16 12:01:00
matplotlib教程——强大的python作图工具库
2021-05-18 23:42:55
![](https://img.aspxhome.com/file/2023/9/72719_0s.jpg)
Python知识点详解之正则表达式语法
2022-02-08 17:01:31
《写给大家看的设计书》阅读笔记之色彩
2009-07-30 12:45:00
![](https://img.aspxhome.com/file/UploadPic/20097/30/color-85s.jpg)
Django CBV与FBV原理及实例详解
2023-02-14 20:39:01
![](https://img.aspxhome.com/file/2023/8/93838_0s.png)
概述javascript在Google IE中的调试技巧
2023-08-08 11:50:29
![](https://img.aspxhome.com/file/2023/8/55928_0s.jpg)
python 中的 super详解
2023-09-07 01:27:35
![](https://img.aspxhome.com/file/2023/3/131563_0s.png)
Python3.5 Json与pickle实现数据序列化与反序列化操作示例
2022-04-08 17:53:55
![](https://img.aspxhome.com/file/2023/1/102721_0s.png)