The script utils object gives you access to some useful functions. All you have to do is to type "ScriptUtils." and all the functions available are displayed in an auto completion list.
NOTE! A text string is past as a single quote string argument in a Pascal script, but as a double quote string argument in a C++, VB or Java script.
E.g.
HighlightText('Lorem ipsum') in Pascal script
HighlightText("Lorem ipsum") in C++ script.
Methods
Pos
Syntax
Pos(sSub, sSource: String): Integer
int Pos(String sSub, String sSource)
Description
Find a sub string within the source string. The search starts from the beginning of the source string. The return value is the position of the found sub string. If nothing is found, the function returns 0 (zero).
PosAt
Syntax
PosAt(sSub, sSource: String; index: Integer): Boolean;
bool PosAt(String sSub, String sSource, int index)
Description
Test if a sub string is present in the source string at the given position. The result is true if the sub string is found at the given "index" position.
PosFrom
Syntax
PosFrom(sSub, sSource: String; nFrom: Integer): Integer;
int PosFrom(String sSub, String sSource, int nFrom)
Description
Find a sub string within the source string. The search starts from the "nFrom" position. The return value is the position of the found sub string. If nothing is found, the function returns 0 (zero).
RegExPos
Syntax
RegExPos(sSub, sSource: String; var sExp: String): Integer
int RegExPos(String sSub, String sSource, String &sExp)
Description
Find a sub string within the source string. The search starts from the beginning of the source string. The found expression is stored in the "sExp" variable. The return value is the position of the found sub string. If nothing is found, the function returns 0 (zero).
NOTE! If you use the sExp variable in a JScript you have to initialize the variable with a value first. E.g. var found = "";
Example
// C++ script
int n;
string found;
n = ScriptUtils.RegExPos("[0-9]", "abc123defgh", found);
if (n > 0 { ... }
RegExPosAt
Syntax
RegExPosAt(sSub, sSource: String; index: Integer; var sExp: String): Boolean;
bool RegExPosAt(String sSub, String sSource, int index, String &sExp)
Description
Test if a sub string is present in the source string at the given position. The result is true if the sub string is found at the given "index" position. The variable "sExp" holds the matched expression.
RegExPosFrom
Syntax
RegExPosFrom(sSub, sSource: String; nFrom: Integer; var sExp: String): Integer;
int RegExPosFrom(String sSub, String sSource, int nFrom, String &sExp)
Description
Find a sub string within the source string. The search starts from the "nFrom" position. The return value is the position of the found sub string. If nothing is found, the function returns 0 (zero). The variable "sExp" holds the matched expression.
RegExReplaceAll
Syntax
RegExReplaceAll(const sSource, sFind, sReplace: string): string;
String RegExReplaceAll(String sSource, String sFind, String sReplace)
Description
Replace all expressions found in the string. Return the resulting string.
RightPos
Syntax
RightPos(sSub, sSource: String): Integer;
int RightPos(String sSub, String sSource)
Description
Find a sub string within the source string. The search starts from the end of the string. The return value is the position of the found sub string. If nothing is found, the function returns 0 (zero).
RightPosFrom
Syntax
RightPosFrom(sSub, sSource: String; nFrom: Integer): Integer;
int RightPosFrom(String sSub, String sSource, int nFrom)
Description
Find a sub string within the source string. The search starts from the "nFrom" position and the source string is searched from right to left. The return value is the position of the found sub string. If nothing is found, the function returns 0 (zero).
RunScript
Syntax
RunScript(sCommand, sScript, sInputText: String): String;
String RunScript(String sCommand, String sScript, String sInputText)
Description
Use it to run an external script, e.g. a JavaScript. It should be possible to run any type of script, including JScript, VBScript, PHP, Python ...
The input text is read by the script using stdin (Node script.js < [inputText]). The input text can be an empty string.
Example
{
// Run a JavaScript using NodeJS
var s = Document.SelText;
var sz = "Node";
var sc = "c:\\Users\\Me\\Documents\\Source\\JavaScript\\numsort.js";
var sr = ScriptUtils.RunScript(sz,sc,s);
Document.SelText = sr;
}
StringReplaceAll
Syntax
StringReplaceAll(sSource, sFind, sReplace: String): String;
String StringReplaceAll(String sSource, String sFind, String sReplace)
Description
Replace a string "sFind" with a replacement string "sReplace" in a source string "sSource". Return value is the resulting string.
Example
{
String s = Document.Text;
Document.Text = ScriptUtils.StringReplaceAll(s, "<div>", "<div class=\"foo\">");
}
|