use*_*899 4 transpose replace notepad++
我有一个文本文件:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
Run Code Online (Sandbox Code Playgroud)
我希望输出为:
Line1: 0xC1,0x63,0x3F,0x01,
Line2: 0x80,0x00,0x80,0xA0,
Run Code Online (Sandbox Code Playgroud)
如何使用 Notepad++ 中的替换功能来做到这一点?
您可以使用以下快捷方式在 Notepad ++ 中进行转置
Step 1: Ctrl + A: selects all.
Step 2: Ctrl + J: Transpose the Row you selected
Run Code Online (Sandbox Code Playgroud)
干杯...
Notepad++ 中没有用于转置矩阵的内置函数,并且您无法使用 Replace 来完成此操作(正如 M42 指出的那样)。另外,我不知道有任何相关的插件。因此,您要么需要不同的编辑器,要么使用脚本来完成。我想最简单的解决方案是使用电子表格,例如 Excel 或 OpenOffice,它们都可以让您轻松转置表格。
但是,仍然有一个不错的选择,无需离开 Notepad++。就是用Python Script插件。
Python Script插件,来自Plugin Manager或来自官方网站。Plugins > Python Script > New Script. 为新脚本选择一个文件名(例如transpose.py),然后复制后面的第一个代码块,然后将第二个代码块复制到另一个脚本,例如transpose_uneven.py.Plugins > Python Script > Scripts > transpose.py. 这将打开一个新选项卡,其中包含转置的数据。delimiter=","
newline="\n"
content=editor.getText()
matrix=[line.split(delimiter) for line in content.rstrip(newline).split(newline)]
transposed=list(map(list, zip(*matrix)))
notepad.new()
for line in transposed:
editor.addText(delimiter.join(line) + newline)
if len(transposed)!=len(matrix[0]):
console.clear()
console.show()
console.write("Warning: some rows are of uneven length. You might consider using the transpose_uneven script instead.")
Run Code Online (Sandbox Code Playgroud)
import itertools
delimiter=","
newline="\n"
content=editor.getText()
matrix=[line.split(delimiter) for line in content.rstrip(newline).split(newline)]
transposed=list(map(list, itertools.izip_longest(*matrix, fillvalue="")))
notepad.new()
for line in transposed:
editor.addText(delimiter.join(line) + newline)
Run Code Online (Sandbox Code Playgroud)
该transpose.py脚本将转置以下示例:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
Run Code Online (Sandbox Code Playgroud)
到:
0xC1,0x63,0x3F,0x01
0x80,0x00,0x80,0xA0
,,,
Run Code Online (Sandbox Code Playgroud)
如果某些行不均匀:
0xC1,0x80,
0x63,0x00,
0x3F,0x80,
0x01,0xA0,
0x02
Run Code Online (Sandbox Code Playgroud)
不均匀的列将被相应丢弃:
0xC1,0x63,0x3F,0x01,0x02
Run Code Online (Sandbox Code Playgroud)
如果不需要,请使用它transposed_uneven.py,它将返回:
0xC1,0x63,0x3F,0x01,0x02
0x80,0x00,0x80,0xA0,
,,,,
Run Code Online (Sandbox Code Playgroud)