UltraEdit的脚本使用

 

///////////////////////////////////////////////////////////////////////////////////////

notepad++,双击找文件中相同变量的位置
其实ultraedit也有类似的功能,按住shift键的同时,鼠标双击想要观察的变量,可以看到整个文件该变量都高亮了。
想取消也很简单,ctrl+F,然后Esc即可。

///////////////////////////////////////////////////////////////////////////////////////

 

IDM PowerTips

Integrated scripting engine tutorial

Scripting in UltraEdit/UEStudio is enabled through embedding of the JavaScript engine. This allows users to enjoy the power and flexibility of the JavaScript language while using the UltraEdit/UEStudio Application Object commands to interact with the editor or documents open in the editor (Document Object commands).

The scripting engine supports the core functionality of JavaScript 1.7. Further information on JavaScript 1.7 may be found on the associated Mozilla site.

Using the Integrated Scripting Engine

 

扫描二维码关注公众号,回复: 10546039 查看本文章

Step 1: Create the Script

Create your (JavaScript) script using UltraEdit/UEStudio. As mentioned above, you may use JavaScript 1.7 and the UltraEdit/UEStudio Application Object commands and Document Object Commands.

There is extensive information in the Help regarding the commands available, however we have a few sample scripts below.

The script we've created above is a simple "Hello World" script which will write "Hello World" to the active document.

Step 2: Add the Script

Once you've created (and saved) your script you will need to add it in the Scripting : Scripts dialog.

Click on the "Add" button to add the script to the list. You will need to browse to the location of the script and, if you would like, type a description of the script. The description will display in the Description field in the scripting dialog.

Once the script has been added, you can define a hotkey/chord for a quick and easy execution of the script. Note: You'll need to create a hotkey first before you can set up a chord.

When you are done, you may click OK.

Step 3: Execute the Script

To execute the script go to the Scripting menu. You will see your script name at the bottom of the "Scripts" menu. Click on the script name to execute it. You can also use the Hotkey/Chord if you have defined them.

After executing the above script, you should see the following results:

Note: As the scripting does take advantage of the JavaScript language, you may also write this as a function:

// Hello World Example Script

function hello() {
  UltraEdit.activeDocument.write("Hello World!")
}
hello();

Example Script - Retrieving String User Input

The scripting support allows you to prompt the user for String or Integer data, capture that data in a variable, then use the variable accordingly. The methods used to retrieve the data are "UltraEdit.getValue" and "UltraEdit.getString".

 

Prompt for String Input

To prompt for String input use the "UltraEdit.getString" command. An example of prompting for input and capturing the input as a variable is as follows:

var str = UltraEdit.getString("Please Enter a String:",1);

Capture Input:
In order to capture the data, and NOT write it immediately to the document, you must use the '1' parameter in the getString method.

Write Input:
If you would like to write the user input immediately to the file use '0' as the parameter value.

 

Sample Capture String Input Script

The example below prompts the user for a String and captures it in the variable "str". It will then write "You Entered user input (str)" to the active document. It will write a different response depending on whether "UltraEdit" or "UEStudio" was entered.

If you would like, you may copy the script below and expand upon it.

function strInput() {

  //Get user input
  var str = UltraEdit.getString("Please Enter a String:",1);

  //Output what was entered
  UltraEdit.activeDocument.write("You Entered " + str + "\r\n");

  //Conditional responses
  if (str == "UltraEdit") {
    UltraEdit.activeDocument.write(str + " has an integrated scripting engine.\r\n");
    UltraEdit.activeDocument.write(str + " is a very powerful editor.\r\n");
    UltraEdit.activeDocument.write("\r\n");
  } else if (str == "UEStudio") {
    UltraEdit.activeDocument.write(str + " also has integrated scripting\r\n");
    UltraEdit.activeDocument.write(str + " includes all the functionality of UltraEdit and more.\r\n");
    UltraEdit.activeDocument.write("\r\n");
  } else {
    UltraEdit.activeDocument.write("Sorry, there is no defined output for " + str + "\r\n");
    UltraEdit.activeDocument.write("\r\n");
  }

} //end strInput

strInput();

Note: The command used to write to the active document is "UltraEdit.activeDocument.write"

The results after entering "Data", "UltraEdit", and "UEStudio" is as follows:

Example Script - Retrieving Integer User Input

The scripting support allows you to prompt the user for String or Integer data, capture that data in a variable, then use the variable accordingly. The methods used to retrieve the data are "UltraEdit.getValue" and "UltraEdit.getString".

Prompt for Integer Input

To prompt for Integer input use the "UltraEdit.getValue" command. An example of prompting for integer input and capturing the input as a variable is as follows:

var num = UltraEdit.getValue("Please enter an integer",1);

Capture Input:
In order to capture the data, and NOT write it immediately to the document, you must use the '1' parameter in the getValue method.

Write Input:
If you would like to write the user input immediately to the file use '0' as the parameter value.

Sample Capture Integer Input Script

The example below prompts the user for an integer value and captures it in the variable "num". It will write "You Entered user input (str)" to the active document. It will then enter a loop in which it will write "i" number of lines, and number each line.

If you would like, you may copy the script below and expand upon it.

function intInput() {
  //Get user input
  var num = UltraEdit.getValue("How Many Lines:",1);
  //Output what was entered
  UltraEdit.activeDocument.write("You Entered " + num + "\r\n\r\n");
  //Loop 
  var i = 1;
  while (i <= num) {
    UltraEdit.activeDocument.write(i + " \r\n");
    i = ++i;
  }
} //end strInput

intInput();

 

Note: The command used to write to the active document is "UltraEdit.activeDocument.write"

The result after entering "5" is as follows:

Example Script - Enumerate Through All Open Files

Using the Document Object commands, you may access/reference the files that currently open in the editor. If you would like to perform an action/run a script against all open files you would need to retrieve the number of open files, and then loop through each file.

As an example, if you need to find out how many files are open in the editor, you could use the following:

var num_of_docs = UltraEdit.document.length;

If you need to reference a specific file, based on what it was opened, you can do so using UltraEdit.document[x]; where x is the number of the document.

 

Sample Enumerate Through All Open Files

The script below will Enumerate through each open file and write a simple header to each file.

If you would like, you may copy the script below and expand upon it.

// Hello welcome to the UltraEdit scripting environment. Normally you would
// put a header comment at the top of a javascript file to be used in UltraEdit
// in order to indicate the version of the UltraEdit scripting API like so:
// Version = 1.00
// However, this is currently not necessary since the API will default to 1.00.

// ----------------------------------------------------------------------------
// header.js
// This script creates a header for all open documents
// ----------------------------------------------------------------------------
// UltraEdit is our application object. All UltraEdit operations will use this
// object.

// Get the num of open documents.
var num_of_docs = UltraEdit.document.length;

var dashes = "// ------------------------------------------------------------";
dashes += "----------------\r\n";

// Enumerate through all open documents and add the header.
var index;
for (index = 0; index < num_of_docs; index++) {
  UltraEdit.document[index].top();
  UltraEdit.document[index].write(dashes);
  UltraEdit.document[index].write("// Script Name: \r\n");
  UltraEdit.document[index].write("// Creation Date: \r\n");
  UltraEdit.document[index].write("// Last Modified: \r\n");
  UltraEdit.document[index].write("// Copyright (c)20XX\r\n");
  UltraEdit.document[index].write("// Purpose: \r\n");
  UltraEdit.document[index].write(dashes);
} //end for loop

After running the above script, every open file now has the following header:

Enjoy the power of the integrated scripting engine!

 

///////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////

 

造数据可能是日常开发测试中的一项常见工作。笔者当前的项目中需要对系统中的历史数据进行统计分析,由于项目处于初级阶段,数据量比较小,所谓的“历史”数据更是无从获取,于是就需要根据现有的数据编造一些数据来进行功能测试。

        造数据的工具可能有很多,我们甚至可以编写一个java程序直接用jdbc操作数据库,来批量生成数据。笔者使用的UltraEdit拥有强大的列操作功能,同时笔者还想挖掘一下其强大的脚本功能,于是着手写了一个js脚本。基本思想是:从数据库中导出现有数据的sql语句,用脚本找到其中需要替换的部分,乘以给定的系数作为新数据。

        首先是从数据库中导出现有的数据,例如笔者需要的数据表中有70条数据,导出的sql语句类似下列语句:

Insert into T_REPORTSYNTHESIS (REPORTCODE,ZONEID,STATISTICDATE,DEVNAME,REPORTDATA,DATAUNIT) values ('1','320200',to_timestamp('01-11月-13','DD-MON-RR HH.MI.SSXFF AM'),'011000',’1262’,null);

              这70条数据是2013年11月1日的数据,现在我们来模拟70条2012年11月1日的数据。利用UltraEdit的列模式,我们可以很方便地将这70条数据的年份改为2012年,在id(REPORTCODE)为一位的行id前面加上’10’,在id为两位的行id前面’1’,这就得到了id为101到170之间的新的70条数据。

        改变了数据的日期还不够,我们还需要修改各条数据的值(REPORTDATA列,上面sql语句标为黄色的部分)。这时候就轮到js脚本大显身手了:

var ln = parseInt( UltraEdit.getString("从哪一行开始?",1) );

var doc = UltraEdit.activeDocument;

doc.findReplace.regExp = true; // 开启正则表达式

UltraEdit.perlReOn();//启用正则表达式的perl模式

var whatToFind = "(?=.+')(\\d)+(\\.\\d+)?(?=',null)";

//doc.top();

doc.gotoLine(ln, 0);

//doc.write(UltraEdit.regexMode.toString());

var ratio = parseFloat( UltraEdit.getString("输入转换比率",1) );

while(doc.findReplace.find(whatToFind)) {

         var found = doc.selection;

         var whatToReplace = parseFloat(found)*ratio;

//      doc.write(ratio.toString());

         //很不人性化的一点:数字必须转化为字符串!

         doc.findReplace.replace(found,whatToReplace.toString());

}

             脚本里比较重要的是正则表达式,我们需要用一个正则表达式精确定位到待修改的数据列:

var whatToFind = "(?=.+')(\\d)+(\\.\\d+)?(?=',null)";

             这个正则表达式选择了前面是单引号,后面是“’,null”的一串数字(整数或浮点数)。其中用到了零宽度断言和负向零宽度断言,关于正则表达式的技术细节,详见笔者的另一篇博文《正则表达式--笔记与实战(Eclipse文本替换)》。

        要在UltraEdit的脚本里启用这种复杂的正则表达式,需要启用正则表达式的perl模式:

UltraEdit.perlReOn();

             为了使用起来更方便,我们两次调用UltraEdit.getString,分别来动态获取要开始处理的起始行数,以及我们造数据使用的一个系数:我们将使用这个系数乘以现有的数据,例如乘以1.25,即可造出一批比现有数据大25%的新数据,let’s do it !

             我们将上文提到的那段代码保存为一个js文件,例如“reduceSelectedNumByPercent.js”,然后点击“脚本”菜单中的“脚本”项,添加这个脚本文件到菜单下方的列表,然后在需要运行脚本的编辑视图下,点击菜单下方的脚本项即可,现在,用这个文本编辑器尽情的造数据吧!造完之后,当然不要忘了在你的数据库客户端执行最终的Sql语句。

        利用脚本,我们可以直接在编辑器中,“可视化”地完成很多强大的功能,大家一起来挖掘吧。下面附上UltraEdit官方关于脚本的说明文档:

UltraEdit/UEStudio 的脚本通过嵌入 JavaScript 引擎启用。 这允许用户在享受完整 JavaScript 语言的强大和灵活的同时使用以下指定的命令与编辑器(应用程序对象命令),或在编辑器中打开的文档(文档对象命令)进行特别交互。 脚本可以在 UltraEdit/UEStudio 中编辑,在默认词语文件中带有内置 JavaScript 的语法加亮:

脚本引擎支持 JavaScript 1.7 的核心功能。 有关 JavaScript 的更多信息,请参考相关的 Mozilla 网站 (http://developer.mozilla.org/en/docs/JavaScript)。

例如,该脚本将生成一系列数字并将其写入活动的文档:

function recall(num) {

    UltraEdit.activeDocument.write(num + "\r\n");

}

function num() {

    var i = 0, j = 1, n = 0;

    while (n < 10) {

        recall(i);

        var t = i;

        i = j;

        j += t;

        n++;

    }

}

num();

更多演示脚本位于安装目录的“scripts”子目录下。要查看简短的脚本指南,请点击这里。

在脚本中包含脚本

需要的话,用户可以在脚本中包含一个外部脚本,参考以下的方法:

// include externalScript.js

// include C:\full path\to external\script\externalScript.js

这个包含命令必须在前面加上行注记符。如果一个用户因调试的原因要排除这个包含的脚本,所包含的内容可以以两个行注记排除,如:

// // include externalScript.js

预设变量值

UltraEdit 支持一些变量值,当每次 UltraEdit 有脚本启动时它们会被初始化为预设值:

区块模式均为关闭。

十六进制模式均为关闭。

插入模式均为打开。

正则表达式引擎均设置为 Perl。

这些项会在每次运行一个脚本时被设置。

应用程序对象命令

UltraEdit 是全部 UltraEdit 操作所基于的应用程序对象。以下命令作用于编辑器而非活动文档。 除非注明其他参数,否则所有应用程序对象命令都必须使用下列格式调用:

UltraEdit.commandName();

下表说明了应用程序对象命令:

命令

参数*

说明

clearClipboard

清除活动的剪贴板。

clipboardContent

** 这是只读属性。

返回当前剪贴板内容。例如:

var clip = UltraEdit.clipboardContent;

clipboardIdx

** 这是只读属性。

返回当前剪贴板的索引。例如:

var clip = UltraEdit.clipboardIdx;

closeFile

文件路径

保存模式

0 - 提示保存

1 - 保存并关闭

2 - 关闭不保存

关闭活动的文件。例如:

UltraEdit.closeFile("C:\\temp\\test.txt",2);

*注意:在参数中使用的任何反斜线必须按以上显示进行换码(即使用“\\”而非“\”)。

columnMode

** 这是只读属性。

返回布尔值说明列模式是否活动。例如:

var columnActive = UltraEdit.columnMode;

columnModeOff

关闭列模式。例如:

UltraEdit.columnModeOff();

*注意:脚本处理完成后当前列模式状态将恢复。

columnModeOn

打开列模式。例如:

UltraEdit.columnModeOn();

decryptFilePrompt

显示解密文件对话框。 例如:

UltraEdit.decryptFilePrompt();

encryptFilePrompt

显示加密文件对话框。 例如:

UltraEdit.encryptFilePrompt();

frInFiles

.directoryStart          字符串     搜索开始的

完整路径

.filesToSearch  整数         值:

0 - 列出的文件

1 - 打开的文件

2 - 收藏的文件

3 - 项目文件

4 - 解决方案文件

.matchCase     布尔值     true/false

.matchWord     布尔值     true/false

.regExp    布尔值     true/false

.searchSubs     布尔值     true/false

.unicodeSearch         布尔值     true/false

.searchInFilesTypes 字符串     搜索的文件/类型

范围

.find ("要搜索的字符串");

.replace ("要搜索的字符串", "替换字符串");

** 仅在替换中使用 **

.logChanges     布尔值     true/false

.preserveCase 布尔值     true/false

** 仅无法在替换中使用 **

.useOutputWindow 布尔值     true/false

在指定的文件中搜索,基于指定的参数查找引号 "" 中的字符串。

在文件中查找示例:

UltraEdit.frInFiles.directoryStart = "c:\\temp\\";

UltraEdit.frInFiles.searchInFilesTypes = "*.txt";

UltraEdit.frInFiles.useOutputWindow = true;

UltraEdit.frInFiles.find("3939");

在文件中替换示例:

UltraEdit.frInFiles.directoryStart = "c:\\temp\\";

UltraEdit.frInFiles.searchInFilesTypes = "*.txt";

UltraEdit.frInFiles.useOutputWindow = true;

UltraEdit.frInFiles.replace("3939", "7878");

getString

在提示对话框中使用的引号 ("") 中的字符串

可选参数:

0 int

1 int 返回值

提示用户在当前位置插入的字符串。 “提示”是指脚本运行时显示给用户的提示或问题。例如:

UltraEdit.getString("What is your name?");

var str = UltraEdit.getString("What is your name?",1);

如果使用 int 值“1”,则输入的字符串将不会写入活动文件,但会另存为变量值并在运行的脚本中使用。

 

getValue

在提示对话框中使用的引号 ("") 中的字符串

可选参数:

0 int

1 int 返回值

提示用户在当前位置插入的值。 “提示”是指脚本运行时显示给用户的提示或问题。例如:

UltraEdit.getValue("How old are you?");

var str = UltraEdit.getValue("How old are you?",1);

如果使用 int 值“1”,则输入的字符串将不会写入活动文件,但会另存为变量 int 值并在运行的脚本中使用。

insertMode

更改文本编辑模式中的字符输入为插入模式。

insOvrMode

** 这是只读属性。

返回布尔值说明插入模式是否打开。例如:

var insertActive = UltraEdit.insOvrMode;

messageBox

消息文本位于引号 ("") 中

标题文本位于引号 ("") 中(可选)

显示带有“确定”按钮的消息对话框。例如:

UltraEdit.messageBox("Can't complete process", "Process Abort");

newFile

打开新的空白文件。

open

文件名在引号("")中

打开指定的文件。文件名必须在引号中。可以使用“^c”且 UltraEdit 会将其替换为剪贴板中的内容。例如:

UltraEdit.open("c:\\temp\\test.txt");

UltraEdit.open('^c');

UltraEdit.open("c:\\temp\\^c");

UltraEdit.open("FTP::myserver.com\\/home/mypath/

public_html|index.html");

overStrikeMode

将文本编辑模式更改为输入字符的改写模式。

perlReOn

将正则表达式切换为符合 Perl 样式的正则表达式。

regexMode

** 这是只读属性。

返回数值表示活动的正则表达式类型。

0 = UltraEdit 表达式

1 = Unix 表达式

2 = Perl 表达式

例如:

var regexType = UltraEdit.regexMode;

runTool

引号 ("") 中的字符指定要运行的工具的区分大小写的菜单名。

运行一个工具。该工具必须从高级菜单中的工具配置进行配置。例如:

UltraEdit.runTool("Script Tool");

save

保存活动文件

saveAll

保存所有活动文件

saveAs

文件名在引号("")中

将活动文件用指定的文件名保存。文件名必须在引号中。文件名中可以使用“^s”。UltraEdit 将其取代为活动窗口中当前选中的文本。同样可以使用“^c”且 UltraEdit 会将其替换为剪贴板中的内容。

UltraEdit.saveAs("c:\\temp\\test.txt");

UltraEdit.saveAs("^s");

UltraEdit.saveAs("^c");

selectClipboard

剪贴板号码 (0-9)

选择指定的剪贴板 0 = Windows 剪贴板,1-9 表示用户剪贴板。例如:

UltraEdit.selectClipboard(2);

ueReOn

将正则表达式切换为 UltraEdit 样式的正则表达式。

unixReOn

将正则表达式切换为 Unix 样式的正则表达式。

文档对象命令

document 是 JavaScript 阵列对象,阵列对象是UltraEdit 应用程序对象的属性。 这是所有当前同时打开文档的阵列。activeDocument 参数可以用来指定要写入活动文件的输出,或者用户可以根据文件选项卡顺序指定文件的索引(即文档 [0], ... 文档 [8])。 例如:

UltraEdit.activeDocument.write("test");

将“test”写入当前文档,同时以下:

UltraEdit.document[4].write("test");

将允许用户打开多个文件并将指定的文本写入打开待编辑的第五个文件(根据文件标签的顺序)。

脚本中可以使用“//”进行注释,用于测试和文档。

脚本一旦创建后便可以编辑。请注意,“^c”和“^s”可能在很多脚本中应用,使用时将取代剪贴板中的内容(^c)和当前选中的内容(^s)。这允许用户创建引用特定字符串的脚本,并将字符串用 ^c 或 ^s 取代,以便在脚本运行时动态地“指定”字符串。以下命令作用于当前打开的文档进行编辑。 除非注明其他参数,否则所有文档对象命令都必须使用下列格式调用:

UltraEdit.activeDocument.commandName();

下表说明了文档对象命令:

命令

参数*

说明

ansiToOem

将文件从 ANSI 转换为 OEM。例如:

UltraEdit.activeDocument.ansiToOem();

ASCIIToUnicode

转换 ASCII 文件到 Unicode

ASCIIToUTF8

转换 ASCII 文件到 UTF-8

bottom

跳转到文件结尾。

cancelSelect

清除活动文档中的任何选择。示例: UltraEdit.activeDocument.cancelSelect();

clearAllBookmarks

清除活动文档中的所有书签。例如:

UltraEdit.activeDocument.clearAllBookmarks();

codePage

** 这是一个活动/指定文件的属性。

回传活动文件的页码值。例如:

var cp = UltraEdit.activeDocument.codePage;

可用来设置活动文件要使用的页码。例如:

UltraEdit.open("C:\\temp\\korean_file.txt")

UltraEdit.activeDocument.codePage = 949;

collapseAll

折叠活动文件中所有可折叠的文本。 例如:

UltraEdit.activeDocument.collapseAll();

columnCenterJustify

将选中的列居中调整。

columnCut

要剪切的列编号数值

在列模式中剪切选中的列或从当前光标位置到文件末尾的指定数量的列。要剪切选中的列必须使用值“0”。

columnDelete

要删除的列编号数值

在列模式中删除选中的列或从当前光标位置到文件末尾的指定数量的列。要删除选中的列必须使用值“0”。

columnInsert

字符串位于引号 ("") 中

将引号中的字符串插入选中的列。

columnInsertNum

起始数字         整数        

增量         整数        

列首补零         布尔值     true/false

十六进制         布尔值     true/false

将数字插入选中的列。 如果没有选中的内容,则插入将从光标位置移至文件的最后一行。例如:

UltraEdit.activeDocument.columnInsertNum(2, 3 , false, true);

columnLeftJustify

将选中的列居左调整。

columnRightJustify

将选中的列居右调整。

copy

将选中的文本复制到剪贴板。如果没有选中的内容,如果配置了当没有活动的选择时,启用当前行复制/追加选项,当前光标位置所在的行将被复制。

copyAppend

复制选中的文本并将其追加到剪贴板。如果没有选中的内容,如果配置了当没有活动的选择时,启用当前行复制/追加选项,当前光标位置所在的行将被复制。

copyFilePath

将活动文件的路径/名称复制到剪贴板。

currentChar

** 这是活动/指定文档的只读属性。

返回光标处字符的值。例如:

var char = UltraEdit.activeDocument.currentChar;

currentColumnNum

** 这是活动/指定文档的只读属性。

返回当前列号的值。 第一列编号为“0”。例如:

var col = UltraEdit.activeDocument.currentColumnNum;

currentLineNum

** 这是活动/指定文档的只读属性。

返回当前行号的值。例如:

var lineNum = UltraEdit.activeDocument.currentLineNum;

currentPos

** 这是活动/指定文档的只读属性。

返回值为当前位置到文件开头的字节数。例如:

var pos = UltraEdit.activeDocument.currentPos;

cut

将选中内容从文件剪切到剪贴板。 如果没有选中的内容,则将剪切光标位置目前所在的行。

cutAppend

将选中内容从文件中剪切并追加到剪贴板。 如果没有选中的内容,则将剪切光标位置目前所在的行。

deleteText

删除当前字符或选中的文本。

deleteLine

删除当前的行。

deleteToEndOfLine

将从光标位置开始删除一直到行的结尾。

deleteToStartOfLine

将从光标位置开始删除一直到行的开始。

dosToMac

将文件(行终止符)转换为 MAC 格式。

dosToUnix

将文件(行终止符)转换为 UNIX 格式。

dupeLine

在光标下插入活动行的复制。

encoding

** 这是一个活动/指定文件的唯读属性。

回传活动文件的编码值。例如:

var enc = UltraEdit.activeDocument.encoding;

endSelect

停止选择文本(详细信息请参见 startSelect)。

expandAll

展开活动文件中所有折叠的文本。 例如:

UltraEdit.activeDocument.expandAll();

fileSize

** 这是活动/指定文档的只读属性。

返回引用文件的字节数大小。例如:

var size = UltraEdit.activeDocument.fileSize;

findReplace

.matchCase     布尔值     true/false

.matchWord     布尔值     true/false

.mode       整数         值:

0 - 当前文件

1 - 在选择中

2 - 所有打开的文件

.regExp    布尔值     true/false

.searchAscii     布尔值     true/false

.searchDown   布尔值     true/false

.searchInColumns   布尔值     true/false

.fromCol  整数         default: 0

.toCol       整数         default:

-1

.find ("要搜索的字符串");

.replace ("要搜索的字符串", "替换字符串");

** 仅在替换中使用 **

.preserveCase 布尔值     true/false

.replaceAll        布尔值     true/false

.replaceInAllOpen    布尔值     true/false

*在替换中取代 .mode

.selectText       布尔值     true/false

*仅替换选中的文本

根据指定的参数查找引号 "" 中的字符串。例如:

UltraEdit.activeDocument.findReplace.matchWord = true;

UltraEdit.activeDocument.findReplace.find("3939");

UltraEdit.document[0].findReplace.matchWord = true;

UltraEdit.document[0].findReplace.matchCase = true;

UltraEdit.document[0].findReplace.replace("Copper", "Silver");

请注意:所有属性一旦设定便应用于之后的所有查找和替换,直到再次被设置为其他值。

fromEBCDIC

将文本转换为 EBCDIC 格式。

gotoBookmark

跳转到的书签索引或 -1 转到下一个书签

跳转到下一个/指定的书签。索引从 0 开始。如果用户输入大于实际书签数的索引,则将自动引导到第一个书签(索引 0)。例如:

UltraEdit.activeDocument.gotoBookmark(0);

gotoBookmarkSelect

跳转到的书签索引或 -1 转到下一个书签

跳转到下一个/指定的书签并选择从光标位置到书签的文本。索引从 0 开始。如果用户输入大于实际书签数的索引,则将自动引导到第一个书签(索引 0)。例如:

UltraEdit.activeDocument.gotoBookmarkSelect(0);

gotoEndOfNextWord

跳转到下一个词语的尾部。示例: UltraEdit.activeDocument.gotoEndOfNextWord();

gotoEndOfNextWordSelect

跳转到下一个词语的尾部并选择当前插入记号位置的所有文本。示例: UltraEdit.activeDocument.gotoEndOfNextWordSelect();

gotoEndOfPrevWord

跳转到前一个词语的尾部。示例: UltraEdit.activeDocument.gotoEndOfPrevWord();

gotoEndOfPrevWordSelect

跳转到前一个词语的尾部并选择当前插入记号位置的所有文本。示例: UltraEdit.activeDocument.gotoEndOfPrevWordSelect();

gotoLine

要跳转到的行和列数的数值

跳转到指定的行和列号。使用行号 0 跳转到当前行的指定列。例如:

UltraEdit.activeDocument.gotoLine(1,5);

gotoLineSelect

要跳转到的行和列数的数值

跳转到指定的行号和列号并选择从光标位置到行/列的文本。选择文本时使用行号 0 跳转到当前行的指定列。例如:

UltraEdit.activeDocument.gotoLineSelect(1,5);

gotoPage

要跳转到页面的编号

跳转到指定的页号。例如:

UltraEdit.activeDocument.gotoPage(5);

gotoPageSelect

要跳转到页面的编号

跳转到指定的页号并选择从光标位置到页的文本。例如:

UltraEdit.activeDocument.gotoPageSelect(5);

gotoPos

数字值,以字节数指定该位置与文件开始处的距离

跳转到指定位置

gotoPosSelect

数字值,以字节数指定该位置与文件开始处的距离

Jump to specified position (passed as parameter in number of char from beginning of file) while making a selection

hexDelete

指定要删除的字节数的数值

从文件中删除指定数量的字节。

hexInsert

指定要插入字节大小的数字值

将指定数量的字节插入文件。这将插入空格 (HEX 20)。

hexMode

** 这是活动/指定文档的只读属性。

返回布尔值说明十六进制模式是否活动。例如:

var hexActive = UltraEdit.activeDocument.hexMode;

hexOff

关闭十六进制模式——切换到文本模式。

hexOn

打开十六进制模式。

hideOrShowLines

隐藏选中的行,或如果隐藏则显示在光标行处隐藏的行。

insertLine

在光标当前位置的下面插入空白行。

insertPageBreak

在文件光标目前所在位置插入换页/分页符。

insertTemplate

引号中是后跟点号的模板组名称 ("glo.")(可选)

引号中的模板名称 ("templateName")

全局模板索引(传统)

把指定的模板插入文件中。通过指定模板名称(可指定亦可不指定模板组名称)即可插入全局模板。例如:

UltraEdit.activeDocument.insertTemplate("userTime");

如有必要,用户可以指定全局 ("glo" 或 "global")、环境("env" 或 "environment")、语言("lng" 或 "language")和项目("prj" 或 "project")组以及模板名称。例如:

UltraEdit.activeDocument.insertTemplate("glo.userTime");

UltraEdit.activeDocument.insertTemplate("global.userTime");

UltraEdit.activeDocument.insertTemplate("env.Power1");

UltraEdit.activeDocument.insertTemplate("environment.Power1");

UltraEdit.activeDocument.insertTemplate("lng.class");

UltraEdit.activeDocument.insertTemplate("language.class");

UltraEdit.activeDocument.insertTemplate("prj.noDesc");

UltraEdit.activeDocument.insertTemplate("project.noDesc");

如有必要,用户可以根据索引指定全局模板。例如:

UltraEdit.activeDocument.insertTemplate(0);

insertTemplate

模版索引

将指定的模版插入文件。例如:

UltraEdit.activeDocument.insertTemplate(0);

invertCase

转换所选文本的大小写。

isCharGt

"字符"

检查当前光标位置所在的字符是否大于指定的字符。例如:

if (UltraEdit.document[1].isCharGt('k')){

//do these commands...

} else {

//do these commands...

}

isChar

"字符串"

检查当前光标位置所在的字符是否为指定的字符。 例如:

if (UltraEdit.document[1].isChar('k')){

//do these commands...

} else {

//do these commands...

}

isColNum

数字

检查当前光标位置是否为指定的列号。 例如:

if (UltraEdit.activeDocument.isColNum(13)){

//do these commands...

} else {

//do these commands...

}

isColNumGt

数字

检查当前光标位置是否大于指定的列号。 例如:

if (UltraEdit.activeDocument.isColNumGt(13)){

//do these commands...

} else {

//do these commands...

}

isEof

检查当前光标位置是否为文件的结尾。 例如:

if (UltraEdit.document[1].isEof()){

//do these commands...

} else {

//do these commands...

}

isExt

"字符串"

检查活动文件的文件扩展名是否与指定字符串匹配。例如:

if (UltraEdit.document[1].isExt("txt")){

//do these commands...

} else {

//do these commands...

}

isFound

检查脚本中上次找到的命令结果,并根据结果有条件地执行其他命令。例如:

UltraEdit.activeDocument.findReplace.find("string");

if (UltraEdit.activeDocument.isFound()){

//do these commands...

} else {

//do these commands...

}

isFTP

检查当前文件是否为通过 FTP/SFTP 加载的文件,而不是本地/网络文件。

if (UltraEdit.document[1].isFTP()){

//do these commands...

} else {

//do these commands...

}

isHexModeOn

检查当前文件是否设置为十六进制/二进制模式。

if (UltraEdit.activeDocument.isHexModeOn()){

//do these commands...

} else {

//do these commands...

}

isName

"字符串"

检查活动文件的文件名(不是路径或扩展名)是否与指定字符串匹配。例如:

if (UltraEdit.document[1].isName("foo")){

//do these commands...

} else {

//do these commands...

}

isNotFound

检查脚本中上次找到的命令结果,并根据结果有条件地执行其他命令。例如:

UltraEdit.activeDocument.findReplace.find("string");

if (UltraEdit.activeDocument.isNotFound()){

//do these commands...

} else {

//do these commands...

}

isReadOnly

此命令检查活动文档是否设置为只读。 例如:

if (UltraEdit.activeDocument.isReadOnly()){

//do these commands...

} else {

//do these commands...

}

isSel

检查活动文件中当前有没有选中的文本。 例如:

if (UltraEdit.document[1].isSel()){

//do these commands...

} else {

//do these commands...

}

isWordWrap

此命令检查活动文档的自动换行状态。 例如:

if (UltraEdit.activeDocument.isWordWrap()){

//do these commands...

} else {

//do these commands...

}

key

BACKSPACE

DEL

DOWN ARROW

END

HOME

LEFT ARROW

PGDN

PGUP

RIGHT ARROW

UP ARROW

CTRL+END

CTRL+HOME

CTRL+LEFT ARROW

CTRL+RIGHT ARROW

将键盘命令插入活动文件。通常用于在文件中导航以及退格或删除。“CTRL+”修改符可以用于常规编辑修改命令。

如果要输入文本,则使用“write”命令而非“key”命令。 例如:

UltraEdit.activeDocument.key("BACKSPACE");

UltraEdit.activeDocument.key("CTRL+RIGHT ARROW");

length

** 这是活动/指定文档的只读属性。

返回活动文档的数量。 例如:

var num_of_docs = UltraEdit.document.length;

lineTerminator

** 这是一个活动/指定文件的唯读属性。

回传一个活动文件用来表示行终止字符的数值。例如:

var lt = UltraEdit.activeDocument.lineTerminator;

0 = DOS

1 = UNIX

2 = MAC

matchBrace

查找下一个匹配的括号并选择括号中的文本。

moveLineDown

在活动文档中将当前行下移一行。 例如:

UltraEdit.activeDocument.moveLineDown();

moveLineUp

在活动文档中将当前行上移一行。 例如:

UltraEdit.activeDocument.moveLineUp();

oemToAnsi

将文件从 OEM 转换为 ANSI。

paste

将剪贴板中的内容粘贴到文件中。

path

** 这是活动/指定文档的只读属性。

返回指定文件的完整路径。例如:

var text = UltraEdit.activeDocument.path;

previousBookmark

跳到上一个书签。例如:

UltraEdit.activeDocument.previousBookmark();

previousBookmarkSelect

跳转到上一个书签并选择从光标位置到书签的文本。例如:

UltraEdit.document[1].previousBookmarkSelect();

readOnlyOff

将活动文档设置为可写

readOnlyOn

将活动文档设置为只读

reIndentSelection

重新缩进当前选中的文本。 例如:

UltraEdit.activeDocument.reIndentSelection();

returnToWrap

将当前选中的硬回车转换为自动换行。

selectAll

选中文件中的全部文本。

selection

** 这是活动/指定文档的只读属性。

返回当前选中的文本。例如:

var text = UltraEdit.activeDocument.selection;

selectLine

选择活动行中的所有文本。

selectToBottom

选择从当前位置到文件末尾的所有文本。

selectToTop

选择从当前位置到文件开头的所有文本。

selectWord

选中当前词语(与双击词的作用相同)。

setActive

将指定文档设置为活动文档。例如:

UltraEdit.document[1].setActive();

sort

.ascending        boolean true/false

.col1Start          int start column key 1

.col1End   int end column key 1

.col2Start          int start column key 2

.col2End   int end column key 2

.col3Start          int start column key 3

.col3End   int end column key 3

.col4Start          int start column key 4

.col4End   int end column key 4

.ignoreCase     boolean true/false

.removeDuplicates 

int    0 - false

1 - all keys match

2 - any keys match

.remKey1 boolean true/false

.remKey2 boolean true/false

.remKey3 boolean true/false

.remKey4 boolean true/false

.type        

int    0 - character order

1 - numeric sort

2 - use locale

3 - alt. sort

Sort the file, or selected text according to specified parameters.

 

Example:

UltraEdit.activeDocument.sort.ascending = true;

UltraEdit.activeDocument.sort.ignoreCase = false;

UltraEdit.activeDocument.sort.removeDuplicates = 1;

UltraEdit.activeDocument.sort.remKey1 = true;

UltraEdit.activeDocument.sort.remKey2 = true;

UltraEdit.activeDocument.sort.type = 0;

UltraEdit.activeDocument.sort.col1Start = 1;

UltraEdit.activeDocument.sort.col1End = 15;

UltraEdit.activeDocument.sort.col2Start = 35;

UltraEdit.activeDocument.sort.col2End = 50;

UltraEdit.activeDocument.sort.sort();

sortAsc

sortDes

类型归类

0 - 根据字符顺序归类。

1- 根据数字值而非字符顺序归类。

2 - 指定归类必须针对现场。

3 -指定归类应使用其他归类方法。使用其他归类方法只需使用一个归类键。

忽略大小写 布尔值 true/false

删除重复 布尔值 true/false

归类键 int 可以指定多达四对开始/结束键。

用升序或降序方式排序文件或选定的文本。

例如:

UltraEdit.activeDocument.sortAsc(0, true, true, 1, -1);

例如:

UltraEdit.activeDocument.sortDes(1, true, false, 4, 8);

spacesToTabs

将文件中的空格转换为制表符。这基于配置-自动换行/制表符设置中定义的制表符空格值。 如果制表符空格值设置为 3,则转换为一个制表符需要一组连续的三个空格。小于三个的连续空格都无法转换。

spacesToTabsAll

将文件中的所有空格转换为制表符。这基于配置-自动换行/制表符设置中定义的制表符空格值。 如果制表符空格值设置为 3,则转换为一个制表符需要一组连续的三个空格。小于三个的连续空格都无法转换。

startSelect

开始选择。这将打开选择模式运行。任何光标的移动或放置都伴随选择并选中文本。endSelect 将停止选择模式。已选文本将保持选中状态直到正常编辑时其他命令导致其不被选中。

tabsToSpaces

将文件中的所有制表符转换为空格。

timeDate

将时间和日期插入文件的光标位置。

toCaps

选定文本中的每个词语首字大写。

toEBCDIC

将文本转换为 EBCDIC 格式。

toggleBookmark

在当前行设置或删除书签。

toLower

将选中文本转换为小写。

top

跳转到文件开头。

toUpper

将选中文本转换为大写。

trimTrailingSpaces

切掉当前文件每行尾部的空格。

unicodeToASCII

转换 Unicode 文件到 ASCII。

unixMacToDos

将活动文件(行终止符)从 Mac/Unix 转换为 DOS 格式。

UTF8ToASCII

转换 UTF-8 文件到 ASCII。

wordWrapOff

关闭活动文档的自动换行

wordWrapOn

打开活动文档的自动换行

wrapToReturn

执行换行时所在列的列号。列号为 0 则表示换行发生在窗口边缘

将选中内容从换行转换为硬回车。例如:

UltraEdit.activeDocument.wrapToReturn(60);

write

写入的文本位于引号 ("") 中

将指定的文本写入光标位置。例如:

UltraEdit.activeDocument.write("This is a test.");

UltraEdit.activeDocument.write("^c");

将在 write 命令中使用剪贴板内容。

xmlConvertToCRLF

将单行的 XML 文件转换为缩进的 XML 格式。

输出窗口对象命令

outputWindow 是 JavaScript 阵列对象,阵列对象是UltraEdit 应用程序对象的属性。 除非注明其他参数,否则所有输出窗口对象命令都必须使用下列格式调用:

UltraEdit.outputWindow.commandName();

下表说明了输出窗口对象命令:

命令

参数*

说明

clear

清除输出窗口内容。例如:

UltraEdit.outputWindow.clear();

copy

复制输出窗口的内容到活动剪贴板。例如:

UltraEdit.outputWindow.copy();

showOutput

布尔值 true/false

确定是否显示写入输出窗口中的针对用户数据。 现在只包含 outputWindow.write()。例如:

UltraEdit.outputWindow.showOutput=false;

showStatus

布尔值 true/false

确定是否在输出窗口中显示所有状态信息(脚本名称、脚本成功/失败和错误信息)。例如:

UltraEdit.outputWindow.showStatus=true;

showWindow

布尔值 true/false

切换输出窗口是否可见。例如:

UltraEdit.outputWindow.showWindow(true);

visible

** 这是只读属性。

返回布尔值表示输出窗口是否可见。例如:

UltraEdit.outputWindow.visible;

write

写入的文本位于引号 ("") 中

向输出窗口中写入指定的文本。 这将每次仅支持一行且不包含行终止符。例如:

UltraEdit.outputWindow.write("This is a test.");

 

发布了16 篇原创文章 · 获赞 44 · 访问量 38万+

猜你喜欢

转载自blog.csdn.net/Game_jqd/article/details/104540662
今日推荐