简体   繁体   English

如何搜索和摆脱这个角色?

[英]How to search and get rid of this character?

Bulmaca-Zeka Oyunu<200f>

I have a lot of strings in a text file, and I noticed that one has this <200f> char.我在一个文本文件中有很多字符串,我注意到一个有这个 <200f> 字符。 I want to find all entries that have this char and remove it.我想找到所有具有此字符的条目并将其删除。 But in Vim I can't find it by searching '<200f>' using the search string '<200f>'.但在 Vim 中,我无法通过使用搜索字符串“<200f>”搜索“<200f>”来找到它。 Probably it is one char not 6 individual chars.可能是一个字符而不是 6 个单独的字符。

In Python or VIM, how to remove or search them?在 Python 或 VIM 中,如何删除或搜索它们?

Those literal characters in angle brackets are how Vim handles some problematic unprintable characters.尖括号中的那些文字字符是 Vim 处理一些有问题的不可打印字符的方式。 They are quite puzzling at first but they are really easy to figure out because they simply spell out the character's hexadecimal code.起初它们很令人费解,但它们真的很容易弄清楚,因为它们只是拼出字符的十六进制代码。

In this case, <200f> is the literal representation of U+200F , which you search like this:在这种情况下, <200f>U+200F的文字表示,您可以这样搜索:

/\%u200f

So, if you want to get rid of the occurrences of <200f> in the current buffer, all you have to do is:因此,如果您想摆脱当前缓冲区中出现的<200f> ,您所要做的就是:

:%s/\%u200f//g

See :help \%u .请参阅:help \%u

You can't find it in vim because you're not searching for the correct string.您在vim中找不到它,因为您没有搜索正确的字符串。 Check your vim documentation: angle brackets are meta-characters.检查您的vim文档:尖括号是元字符。 Simply escape them, and remove the undesired strings.只需将它们转义,然后删除不需要的字符串。

:%s/\<200f\>//g

In Python you could perhaps use string replacement:在 Python 中,您也许可以使用字符串替换:

line_of_text = "Bulmaca-Zeka Oyunu<200f>"
print(line_of_text.replace("<200f>", "")

Output: Output:

Bulmaca-Zeka Oyunu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM