- sakura是一款优秀的文本编辑工具,可以通过【设定】→【共通设定】→【宏】追加宏文件。在【Tool】中调用宏。
- sakura也支持宏脚本录制。
- 本文实现了,将当前编辑本文中相同的字符串,按行替换成升序的字符串,注意被替换的字符串每行是唯一的。
替换前:
1行:123,sijs000000000001,456,789
2行:123,sijs000000000001,456,789
3行:123,sijs000000000001,456,789
...
n行:123,sijs000000000001,456,789替换后:
1行:123,sijs000000000001,456,789
2行:123,sijs000000000002,456,789
3行:123,sijs000000000003,456,789
...
n行:123,sijs00000000...... n,456,789
var iLine = 0; var iCount = 0; var iMax = GetLineCount(0); var oSC = new ActiveXObject("ScriptControl"); oSC.Language = "VBScript"; var sFunc = 'Function InBox(prompt, title, default)\n'; sFunc += ' InBox = InputBox(prompt, title, default)\n'; sFunc += 'End Function\n'; oSC.AddCode(sFunc); var Ret = oSC.Run ("InBox", "Replace each line in ascending order according to the same string", "AsceReplaceSameString", "please input be raplaced string"); // 数字字符串自增并保持前导零(例如:0001 → 0002) // 适用格式:前缀+数字(如AAA-000000000001) // 1. 获取替换的字符串 var baseStr = Ret; // 2. 分离前缀和数字部分(适配含连字符的格式,如sij-000000000001) var match = baseStr.match(/^([a-zA-Z-]+)(\d+)$/); //if (!match) { // Alert("格式错误!请确保行内容为「前缀+数字」格式", "错误"); // exit; //} prefix = match[1]; // 前缀部分(如"AAA-") var numStr = match[2]; // 数字字符串(如"000000000001") var digitCount = numStr.length; // 数字位数(用于保持补0长度) var num = 0 var newstr = baseStr GoFileTop(0); while (++iLine <= iMax){ Replace(baseStr, newstr, 30); // 置換 // 3. 数字自增 num = parseInt(numStr, 10) + iLine; // 4. 补0并拼接(保持原数字位数) var newNumStr = num.toString(); // 不足原位数时前补0 while (newNumStr.length < digitCount) { newNumStr = "0" + newNumStr; } // 5. 替换当前行内容 newstr = prefix + newNumStr; iCount++; } var oWsh = new ActiveXObject("WScript.Shell"); var message = iCount.toString() + " strings were replaced" oWsh.Popup(message, 0, "finish", 0);
浙公网安备 33010602011771号