如何在 notepad++ 中为 GPS 坐标将字符填充到不同长度的列

How to pad a character to different length of columns in notepad++ for GPS coordinates

我有这样的坐标:

28.62834,41.11797,0  // every line must be at this lenght
28.62881,41.11737,0
28.6289,41.11725,0   // must add 0 (zero) to 28.6289 , it should look like this: 28.62890
28.62898,41.11716,0
28.629,41.11688,0    // must add two 0 (zero) to 28.629 , it should look like this: 28.62900
28.62935,41.1167,0
28.62978,41.11615,0
28.62996,41.11593,0
28.630,41.115,0      // must add two 0 (zero) to 28.630 , it should look like this: 28.63000 and must add two 0 (zero) to 41.115 , it should look like this: 41.11500,

我想将 0(零)添加到纬度和经度值,使每条线的长度相同。 纬度和经度必须在点后有 5 个数字。示例:28.XXXXX、41.XXXXX

我想要的:

28.62834,41.11797,0
28.62881,41.11737,0
28.62890,41.11725,0
28.62898,41.11716,0
28.62900,41.11688,0
28.62935,41.11670,0
28.62978,41.11615,0
28.62996,41.11593,0
28.63000,41.11500,0

notepad++ 中有简单的方法吗?

两步。

首先在每个太短的数字后加零。将 \b(\d\d\.\d{0,4}), 的正则表达式替换为 00000,.

其次删除多余的零。将 \b(\d\d\.\d{5})0+, 的正则表达式替换为 ,.

解释:

第一个正则表达式找到两个数字,然后是一个点,然后是零到四个移动数字,最后是一个逗号。无需在点后查找五位数字。替换确保每个数字至少有五位数。

第二个正则表达式与第一个相似,但它会查找点后有五位数的数字,然后是一些零,最后是逗号。

这与 this answer 中的非常相似,但正则表达式 add/remove 右侧为零。

您可以在 PythonScript 插件中 运行 python 脚本。

如果还没有安装,按照这个guide

创建脚本(插件 >> PythonScript >> 新脚本)

复制此代码并保存文件(例如format.py):

import re
def format(match):
    nums = match.group(1).split(',')
    return "%7.5f,%7.5f;%d" % (float(nums[0]), float(nums[1]), int(nums[2]) )
editor.rereplace('^(.+)$', format)
  • 打开您要更改的文件
  • 运行 脚本(插件 >> PythonScript >> 脚本 >> 格式)
  • 完成

假设28.629350,41.1167,0一定是28.62935,41.11670,0

给定示例的结果: