简体   繁体   English

添加一个值并使用 Notepad++ 求和

[英]Add a value and sum it up using Notepad++

I am having a file wherein the data is similar as given below:我有一个文件,其中数据类似于如下所示:

abc - $0.05
xyz - $0.01
rst - $0.09
etc - $0.4

What I want to do is, increment all the values by $0.02 so that the final sum will look like below:我想要做的是,将所有值增加 0.02 美元,以便最终总和如下所示:

abc - $0.07
xyz - $0.12
rst - $0.11
etc - $0.42

How can I achieve this using Notepad++如何使用 Notepad++ 实现此目的

Thank you.谢谢你。

You can run a python script within the PythonScript plugin.您可以在 PythonScript 插件中运行 Python 脚本。

If it is not yet installed, follow this guide如果尚未安装,请按照本指南进行操作

Create a script (Plugins >> PythonScript >> New Script)创建脚本(插件 >> PythonScript >> 新脚本)

Copy this code and save the file (for example calculate.py ):复制此代码并保存文件(例如calculate.py ):

import re
def calculate(match):
    return '%s' % (str(float(match.group(1)) + 0.02))

editor.rereplace('(\d+\.\d+)', calculate)
  • Open the file you want to change打开要更改的文件
  • Run the script (Plugins >> PythonScript >> Scripts >> calculate)运行脚本(插件 >> PythonScript >> 脚本 >> 计算)
  • Done完毕

Result for given example:给定示例的结果:

abc - $0.07
xyz - $0.03
rst - $0.11
etc - $0.42

Note the difference from your expected second line ( xyz - $0.01 becomes xyz - $0.03 and not xyz - $0.12 )请注意与您预期的第二行的差异( xyz - $0.01变为xyz - $0.03而不是xyz - $0.12

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

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