【问题标题】:Search and replace with term list?搜索并替换为术语列表?
【发布时间】:2015-06-06 19:58:12
【问题描述】:

我想知道是否有一个程序可以使用我想要替换的术语列表而不是一个一个地替换。

例子

À=À
â=â
Â=Â
å=å
Å=Å
ã=ã
Ã=Ã

提前谢谢你

我使用 UltraEditpowergrep atm

【问题讨论】:

    标签: search replace ultraedit


    【解决方案1】:

    UltraEdit 具有 2 个自动重新格式化任务的功能:脚本

    请参阅 UltraEdit 论坛主题 When to use Scripts over Macros 了解差异的简要概述。

    UltraEdit 宏

    可以通过简单地记录您在文件上手动执行的替换操作来创建 UltraEdit 宏,或者您直接在 编辑/创建宏 对话框中对其进行编码。

    手动创建如下:

    1. 在菜单项Edit Macro上的Macro菜单中单击UltraEdit
    2. 点击按钮新建宏
    3. 输入为宏名,例如ReplaceEntities
    4. 取消选中宏属性显示此宏的取消对话框
    5. 检查宏属性如果找不到搜索字符串则继续
    6. 如果将来需要通过按键快速执行宏,请指定一个热键或和弦以按键快速执行。
    7. 点击按钮确定
    8. 回到编辑/创建宏,现在选择了新宏,其中 3 行已经存在于编辑字段中,使用宏命令:
      InsertMode
      ColumnModeOffHexOff
    9. 必须在这 3 个宏命令的下方添加此重新格式化任务,下面发布的宏代码行。
    10. 点击按钮关闭并确认问题以使用按钮Yes更新宏。

    然后宏就可以使用了

    • 通过指定的热键/和弦,
    • 在通过视图 - 视图/列表 - 宏列表打开的宏列表中双击它,以防不可见(停靠或浮动),或
    • 使用宏 - 任意/多次播放

    此外,Macro - Play Again 也可以经常使用,具体取决于上次执行的宏。

    除了对话框中已经存在的 3 个标准命令之外,还需要宏代码来替换整个活动文件 HTML 实体,例如:

    Top
    UltraEditReOn
    Find MatchCase "À"
    Replace All "À"
    Find MatchCase "â"
    Replace All "â"
    Find MatchCase "Â"
    Replace All "Â"
    Find MatchCase "å"
    Replace All "å"
    Find MatchCase "Å"
    Replace All "Å"
    Find MatchCase "ã"
    Replace All "ã"
    Find MatchCase "Ã"
    Replace All "Ã"
    

    需要使用Macro - Save All将此UE宏(不带或带有其他UE宏)保存到宏文件中。

    为了以后再次使用这个宏(和其他宏存储在同一个宏文件中),需要使用宏 - 加载来加载宏文件。

    使用宏 - 设置自动加载,可以选择一个宏文件以在 UltraEdit 启动时自动加载,这样宏文件中的宏就可以从一开始就可用,而无需显式加载宏文件。

    以后也可以使用宏 - 删除宏/修改属性来更改宏属性。对宏代码或其属性进行更改后,不要忘记使用宏 - 全部保存,也可以将此更改保存到宏文件中。

    UltraEdit 脚本

    UltraEdit 脚本使用 JavaScript 核心引擎。 UltraEdit 脚本是一个 ASCII/ANSI 文本文件,其中包含 JavaScript 核心代码和额外的 UltraEdit 相关脚本命令。这意味着 UltraEdit 脚本可以像任何其他文本文件一样直接编写,并且不能在对话框中进行编辑。

    与上面的宏完全相同的 UltraEdit 脚本是:

    if (UltraEdit.document.length > 0)  // Is any file opened?
    {
       // Define environment for this script.
       UltraEdit.insertMode();
       UltraEdit.columnModeOff();
       UltraEdit.activeDocument.hexOff();
    
       // Move caret to top of the active file.
       UltraEdit.activeDocument.top();
    
       // Define all parameters for several Replace All in entire active file.
       UltraEdit.ueReOn();
       UltraEdit.activeDocument.findReplace.mode=0;
       UltraEdit.activeDocument.findReplace.matchCase=true;
       UltraEdit.activeDocument.findReplace.matchWord=false;
       UltraEdit.activeDocument.findReplace.regExp=false;
       UltraEdit.activeDocument.findReplace.searchDown=true;
       UltraEdit.activeDocument.findReplace.preserveCase=false;
       UltraEdit.activeDocument.findReplace.replaceAll=true;
       UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
       UltraEdit.activeDocument.findReplace.selectText=false;
       // This property is only available since UE v14.10.
       if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
       {
          UltraEdit.activeDocument.findReplace.searchInColumn=false;
       }
    
       UltraEdit.activeDocument.findReplace.replace("À","À");
       UltraEdit.activeDocument.findReplace.replace("â","â");
       UltraEdit.activeDocument.findReplace.replace("Â","Â");
       UltraEdit.activeDocument.findReplace.replace("å","å");
       UltraEdit.activeDocument.findReplace.replace("Å","Å");
       UltraEdit.activeDocument.findReplace.replace("ã","ã");
       UltraEdit.activeDocument.findReplace.replace("Ã","Ã");
    }
    

    这样的 UltraEdit 脚本应该使用文件扩展名 .js 保存,例如ReplaceEntities.js

    一旦保存了 UE 脚本,就可以通过 Scripting - Scripts 将其添加到 Script List 中,并为该脚本添加一个简短的描述并分配一个热键/和弦到按键快速执行的脚本。

    然后脚本就可以使用了

    • 通过指定的热键/和弦,
    • 通过在 View - Views/Lists - Script ListScripting - Script List 打开的 Script List 中双击它尚不可见(停靠或浮动),或
    • 点击菜单Scripting中的脚本文件名。

    如果 UE 脚本是活动文件并且它被编写为不在活动文档上运行,则该脚本也可以通过 Scripting - Run Active Script 执行。但是大多数像上面这样的脚本都是为了在活动文件上运行而编写的,因此需要将脚本文件添加到脚本列表中才能执行。

    JavaScript 的核心对象和函数没有在 UltraEdit 中的任何地方记录,尽管它们也可以在 UltraEdit 脚本中使用。核心功能的文档可以在Mozilla Developer 站点上找到。

    UltraEdit 的附加脚本命令记录在标题为 Scripting commands 的页面上的 UE 帮助中。另外还有 View - Views/Lists - Tag List 包含标签组 UE/UES Script Commands 以及 UE/UES Macro Commands 以便快速在插入符号当前位置的活动文件中添加 UE 的脚本或宏命令。

    【讨论】:

      【解决方案2】:

      这是我的 umlaut2html-Makro,它可以进行一些自动文本替换。我想它可以作为灵感;-)

      // Lessons learned from Mofi ;-)
      UltraEdit.ueReOn();
      UltraEdit.activeDocument.findReplace.mode=0;
      UltraEdit.activeDocument.findReplace.matchCase=true;
      UltraEdit.activeDocument.findReplace.matchWord=false;
      UltraEdit.activeDocument.findReplace.regExp=false;
      UltraEdit.activeDocument.findReplace.searchDown=true;
      UltraEdit.activeDocument.findReplace.preserveCase=false;
      UltraEdit.activeDocument.findReplace.replaceAll=true;
      UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
      UltraEdit.activeDocument.findReplace.selectText=false;
      UltraEdit.activeDocument.findReplace.regExp=false;
      UltraEdit.activeDocument.findReplace.replace("ä","ä");    
      UltraEdit.activeDocument.findReplace.replace("ö","ö");    
      UltraEdit.activeDocument.findReplace.replace("ü","ü");    
      UltraEdit.activeDocument.findReplace.replace("Ä","Ä");    
      UltraEdit.activeDocument.findReplace.replace("Ö","Ö");    
      UltraEdit.activeDocument.findReplace.replace("Ü","Ü");    
      UltraEdit.activeDocument.findReplace.replace("ß","ß");    
      

      将此保存到您喜欢的任何位置的 .js 文件中(MyDocuments\UE-Scripts 可能是一个不错的选择),然后调用 Script >“Scripts...”和“Add”,导航以选择该 .js 文件。

      【讨论】:

      • 我在 Ultra 编辑中放入了哪些很棒的东西?提前谢谢你。
      • 很抱歉造成混淆 - 我最初选择了错误的宏并忘记了说明。现在已经修改了我的分析器,希望它对你有用:-)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      相关资源
      最近更新 更多