识别并删除奇怪的字符 [英] Identify and remove strange characters

查看:38
本文介绍了识别并删除奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用什么命令来识别和删除形成单词"的某些奇怪字符,例如:

What command can I use to identify and remove certain strange characters that form "words" such as:

í‰äó_
퀌¢í‰ä‰åí‰ä‹¢
it퀌¢í‰ä‰åí‰ä‹¢
í‰äóìgo

来自一系列文件?这些是一些例子...我想删除这种情况.

from a series of files? Those are some examples... I want to remove such occurrences.

推荐答案

从文件中获取数据后,使用 string 模块:

Using the string module after you've gotten the data from the file:

import string
final_str = ''
for char in my_str:
    if char in string.printable:
        final_str += char

单线替代:

''.join([str(char) for char in my_str if char in string.printable])

这篇关于识别并删除奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆