我正在使用Notepad ++编辑一个编码很差的日志文本文件。该程序没有考虑用户的AZERTY键盘布局。结果是一个文本文件如下(示例我编写)
Hi guysm this is Qqron<
I zonder zhen ze cqn go to the szi;;ing pool together
:y phone nu;ber is !%%)@!#@@#(
Cqll ;e/
我需要按如下方式批量替换字符
a > q
q > a
[/0] > 0
! > 1
和其他几个人
是否可以创建要替换的字符表?我是一个初学者,我不知道Notepad ++是否允许运行脚本
答案 0 :(得分:1)
Notepad ++有一个宏录制器,但宏不能用任何文档化的嵌入式语言编写。您可能会记录一个执行70左右搜索和替换操作的宏。见this explanation。有关于&#34; hacking&#34;的一些信息。宏语言here。
显然,Notepad ++并不适用于此任务。 Python解决方案没问题,但Perl最初的意思是完全像这样。这是一个单行班。这适用于Windows。在bash / Linux中,将双引号替换为单引号。
perl -n -e "tr/aqAQzwZW;:!@#$%^&*()m\/</qaQAwzWZmM1234567890:?./;print"
它将执行@ kreativitea的解决方案(我使用他的翻译字符串),读取标准输入并打印到标准输出。
答案 1 :(得分:0)
我不知道Notepad ++。但是如果你的机器上安装了python,你可以使用这个小脚本。
source = """Hi guysm this is Qqron<
I zonder zhen ze cqn go to the szi;;ing pool together
:y phone nu;ber is !%%)@!#@@#(
Cqll ;e/"""
replace_dict = {'a': 'q', 'q': 'a', '[/0]': '0', '!': '1'}
target = ''
for char in source:
target_char = replace_dict.get(char)
if target_char:
target += target_char
else:
target += char
print target
只需根据需要自定义replace_dict变量即可。
答案 2 :(得分:0)
因此,有很多不同类型的AZERTY布局,所以这不是一个完整的答案。但是,它确实通过了你的测试用例,并且可以在python中完成任何单个字符替换的速度(除非你需要考虑unicode)
from string import maketrans
test = '''Hi guysm this is Qqron<
I zonder zhen ze cqn go to the szi;;ing pool together
:y phone nu;ber is !%%)@!#@@#(
Cqll ;e/'''
# warning: not a full table.
table = maketrans('aqAQzwZW;:!@#$%^&*()m/<', 'qaQAwzWZmM1234567890:?.')
test.translate(table)
因此,只要您找到您的用户正在使用的AZERTY版本,您就可以了。只需确保使用AZERTY实现的详细信息正确填写转换表。