- Quote, Str, List
- UnQuote, Val, UnList
- Trunc
- Empty
- Not
- Exist
- ToUpper, ToLower
- SubStr
- Path
- Len
- LenLen, ListLens
- SpecialCharacter, ^
- Rand
- ASCII
- Abs
- Max,Min
- IsNumber
- Sin, Cos
- Arctan
- Exp
- Log
- Sqrt
All names of functions are not case sensitive.
Argument of the function shall not be empty i.e. f( ) causes syntax error. However expression in brakets may be evaluated as empty. For example
arg = A=Quote(arg) // A = "" now
Some of the functions have different names ( aliases). Consider first one as a most recommended.
For most of the functions listed here see Hans’s Scripting Book for more info and more examples. ( pp 82-92)
Quote, Str, List
These three different names mean the same function. In a nutshell, function QUOTE returns argument embraced into straight quotes. For example
Quote(53) = "53" Quote(hahaha) = "hahaha"
If argument already contains straight quotes, every ” is replaced with \”
Quote("53") = "\"53\"" Quote(abc"d"ef) = "abc\"d\"ef"
Alternative names of the function:
Str – to be consistent with VB
List- Because it is possible to use this function to encapsulate list of tokens into one token.
Example:
List("Red","Green","Blue") = "\"Red\",\"Green\",\"Blue\""
Now you can pass this single token into subroutine or return it from subroutine.
If you are trying to pass just these 3 colors “\”Red\”,\”Green\”,\”Blue\”” is not better then “Red”,”Green”,”Blue”. However if some other information should be concatenated, and the length of the color list is not known in advance, then “\”Red\”,\”Green\”,\”Blue\”” is much better.
It is possible to parse correctly
“\”Red\”,\”Green\”,\”Blue\””,”TRUE”
but not
“Red”,”Green”,”Blue”,”TRUE”.
UnQuote, Val, UnList
These three different names mean the same function. This function removes straight quotes from the begin and end of the argument. If first or last char is not a quote error condition is set. If there is escape sequence(s) \”, then ‘\’ before the each quote is removed.
UnQuote("abc\"d\"ef")=abc"d"ef Val("53") = 53 UnList("\"Red\",\"Green\",\"Blue\"") = "Red","Green","Blue"
Trunc
Truncates everything following the last ‘.’ in the string.
For example
Trunc(3.14) = 3 Trunc(-7.8) = -7 Trunc(first.second.third) = first.second
Warning: Do not apply function trunc to a quoted string.
For example
Trunc("a.b") = "a
This halfquoted string will cause error condition not at the script line containing function TRUNC, but when result will be used in any calculations.
Zstrip
removes trailing zeroes. Argument can be just a number or list of numbers.
Example:
Zstrip(12.300,3.4050,-10) = 12.3,3.405,-10
Empty
Returns 1 if argument is empty string and 0 otherwise
Not
Returns 1 if argument is ‘0’ and 0 otherwise.
Exist
This function takes as an argument full path and file name. ( No filenames relative to the current script directory )
Returns 1 if such a file exists, 0 otherwise
For example:
Exist("c:\autoexec.bat") = 1 Exist("c:\bogus\bogus.txt") = 0 ( unless this file really exists on some bogus computer)
In curently shipped version of the Script Engine the function EXIST does not work with long file names.
ToUpper, ToLower
Converts all lower case chars in the argument into upper case and vice versa.
SubStr
This function requires as an argument 3 parameters separated with commas. First one should be a quoted string. Second should be an integer, indicating beginning of the substring. Note that opening quote does not count and the first char after the quote is char #1. Third parameter also shall be an integer indicating the length of the substring.
Function returns substring as defined by the second and third parameters. Returned string is embraced in quotes.
Example
SubStr("123456",2,2) = "23"
Path
Argument of this function should be a quoted string.
Function Path does its best to convert Windows path to Macintosh and vice versa. Result of the function depends on the platform you are using.
For example, when scripting on Windows,
Path("Plugins:Scripts:MyScript.spt")= "Plugins\Scripts\MyScript.spt" Path("c::temp:Scripts:MyScript.spt")= "c:\temp\Scripts\MyScript.spt" Path(":::Plugins:Scripts:MyScript.spt")= "..\..\Plugins\Scripts\MyScript.spt"
If some computations including path and file name are due, one might consider performing them with ‘:’ instead of ‘\’ to avoid \” – confusion at the end of the quoted expression. After all computations are done, use function Path to convert he result into what Windows expects.
Len
Function returns number of tokens in a list
Example
LEN("Red","Green","Blue") = 3 LEN("\"Red\",\"Green\",\"Blue\"") = 1
LenLen, ListLens
Function returns number(s) of chars in every token. Quotes count.
Example
LenLen("Red","Green","Blue") = 5,7,6 LenLen("\"Red\",\"Green\",\"Blue\"") = 28 ( \ before " also counts )
SpecialCharacter, ^
See Hans’s book on p 97. Arguments may use both upper and lower case. Return value is always quoted. Note that ^(DblQt) = “\””.
[Editor’s note: digging the pmscript.exe file in hexadecimal viewer, I found this special characters:]
Tab : tabulation CR : carriage return NewLn : new line NBSl : non breaking ... (?) NBHy : non breaking Hyphen (?) PgN : page number EmSp : em space EnSp : en space ThSp : thin space DisHy : discretionary hyphen DblQt : double quote SngQt : single quote Blt : bullet EnDh : en dash EmDh : em dash NBSp : non breaking space eof : not shure if it is special character
Rand
When supplied with 2 parameters returns random value equidistributed in the segment defined by parameters. If supplied with just one parameter, function considers 0 as a beginning of the segment.
There is no seed value, sequences of a random numbers are repeatable when reentering the script. See examle in the Hans’s book ( p.91) on how to introduce beter stochastic.
gettime >> ...,...,...,...,...,...,...,T,... loop t=1,T%100 x = rand(100) endloop
ASCII
Returns chars by their ascii number.
Example:
ASCII(65)=A ASCII(65,66)=AB
Do not try to obtain comma (,) by ASCII function because such a value shall cause error condition when trying to use it in computations.
It useful to know that ascii number of the straight quote is 92.
Thus expression “c:\temp\”+”test.p65″ will cause an error because \” confusion. At the same time “c:\temp”+quote(ascii(92))+”test.p65” works fine.
Abs
Removes `-‘ at the beginning of the of the parameter string.
Abs(-42) = 42 Abs(-abc) = abc
Max,Min
Accept as an argument list of numbers of any length. Returns one of them – maximal or minimal. Behaviour of the functions is not efined for the case of empty argument.
IsNumber
Returns 1 if argument of the argument is a number, 0 oherwise. If string is quoted, then it is not a number.
Examples:
IsNumber(76) = 1 IsNumber(haha) = 0 Isumber("76")=0
Sin, Cos
Trigonomeric functions. Accept argument in degrees.
Arctan
Argument should not exceed pi/2 by absolute value. Returns value in degrees
Exp
Natural exponential function; base = e = 2.7182818…. Argument should not exceed 230.
Log
Natural logarithm, base e = 2.7182818…, positive number expected as an argument.
Sqrt
Square root, non negative number expected as an argument.
Leave a Reply