String functions
- replace(source, pattern, value [, times])
Returns a string with the occurances of pattern in source
replaced by value. If times is specified then the
replacement will not occur more than the specified number of times,
if it is not specified then all occurances of the pattern are replaced.
ExamplesCode: Select all
[replace("This is a test", " ", "-")] Hero: This-is-a-test [replace("This is a test", " ", "-", 2)] Hero: This-is-a test
- stringToList(source, pattern [, delim])
Creates a string list from the source string splitting the string
into a list based on pattern if delim is specified then
it is used as the delimiter for the new list, otherwise the default value
of ',' is used.
ExamplesCode: Select all
[stringToList("This is a test", " ")] Hero: This,is,a,test [stringToList("1,2,3,4", ",", ":")] Hero: 1:2:3:4
- substring(source, start [, end])
Returns the substring of source starting at start and ending
at end. If end is not specified then the substring extends
to the end of the source string.
ExamplesCode: Select all
[substring("This is a test", 5)] Hero: is a test [substring("This is a test", 5, 7)] Hero: is
- length(string)
Returns the length of string
ExamplesCode: Select all
[length("")] Hero: 0 [length("hello there")] Hero: 11
- upper(string [, number])
Returns an uppercase version of string. If number is
specified then the number of characters that are converted to uppercase
are limited number.
ExamplesCode: Select all
[upper("hello")] Hero: HELLO [upper("hello"), 1] Hero: Hello
- lower(string [, number])
Returns an lowercase version of string. If number is
specified then the number of characters that are converted to lowercase
are limited number.
ExamplesCode: Select all
[lower("HELLO")] Hero: hello [upper("HELLO"), 1] Hero: hELLO
- indexOf(string, substring [, start])
Returns the index of substring in string. If substring
does not occur within string then -1 is returned. If start is
specified then the search will start from that position, otherwise it will
start the search from the beginning of the string.
ExamplesCode: Select all
[indexOf("this is a test", "is")] Hero: 2 [indexOf("this is a test", "is", 3)] Hero: 5 [indexOf("this is a test", "x")] Hero: -1
- lastIndexOf(string, substring)
Returns the index of the last occurance of substring within
string. If substring is not found then -1 is returned.
ExamplesCode: Select all
[lastIndexOf("this is a test", "is")] Hero: 5 [lastIndexOf("this is a test", "x")] Hero: -1
- trim(string)
Returns a copy of string with the leading and trailing whitespace
removed.
ExamplesCode: Select all
[trim(" This is a test ")] Hero: This is a test [length(trim(" a "))] Hero: 1
- strformat(format [, arguments...])
Returns a formatted string.
The format can contain special instructions that are introduced with
the % symbol.
The easiest and probably most useful format instruction is %{varname} which
inserts the value of varname into the string.
ExampleThe following formats are also supported (lower case format arguments performCode: Select all
[h: weaponName = "Long Sword"] [h: maxDam = 8] [strformat("Weapon Name=%{weaponName}; Max Damage=%{maxDam}")] Hero: Weapon Name=Long Sword; Max Damage=8
the same conversion as the lowercase letters but return the result in
uppercase).- %h, %H, %x, %X
Inserts the hexadecimal representation of the corresponding
argument which must be an integer. - %s, %S
Inserts the string representation of the corresponding argument. - %d
Inserts the decimal integer representation of the corresponding argument
that must be an integer value. - %e, %E
Inserts the floating point value from the corresponding argument in
computerized scientific notion. - %f
Inserts the floating point value from the corresponding argument. - %g, %G
Inserts the floating point value from the corresponding argument in
computerized scientific notion or decimal format. - %a, %A
Inserts the floating point value from the corresponding argument
as a hexadecimal floating-point number with a significand and an exponent - %%
Inserts a percent symbol. - %n
Inserts a new line.
- - left justified
- + will always contain a sign character
- (space) will include leading space for positive values
- 0 will be zero padded
- ( will enclose negative numbers in parentheses
Code: Select all
[strformat("%d", 10)] [strformat("%05d", 10)] [strformat("%+d", 10)] Hero: 10 00010 +10 [strformat("%f", -10.502)] [strformat("%g", -10.502)] [strformat("%+e", -10.502)] [strformat("%5.1f", -10.502)] [strformat("%(5.1f", -10.502)] Hero: -10.502000 -10.5020 -1.050200e+01 -10.5 (10.5)
- %h, %H, %x, %X
- matches(string, pattern)
Returns 1 if string matches pattern or 0 if it does not.
ExamplesCode: Select all
[matches("This is a test", "test")] Hero: 0 [matches("test", "test")] Hero: 1
- encode(string)
Encodes a string so that it can safely be embedding withing a property list. - decode(string)
Decodes a string that was encoded with encode().
ExamplesCode: Select all
[h: props1 = "a=1;b=2"] [h: props2 = "c=3;d=4"] [h: props= ";"] [h: props = setStrProp(props, "First", encode(props1))] [h: props = setStrProp(props, "Second", encode(props2))] [decode(getStrProp(props, "First"))] Hero: a=1;b=2
The replace(), stringToList(), and matches() functions all accept a
regular expression as their pattern argument.
For more information on regular expressions read the following
(warning this is advanced so you may have more luck aasking on the
forums on how to achieve what you are trying to do if you don't
usually program).
http://java.sun.com/javase/6/docs/api/j ... ttern.html
http://www.regular-expressions.info/tutorial.html
http://www.tek-tips.com/faqs.cfm?fid=2689
http://java.sun.com/developer/technical ... /1.4regex/
The java code in the above pages can be ignored, the important part is the
regular expression descriptions.
There is also one more string function that deals exclusivley with
regular expressions. strfind(string, pattern).
This function is used to match a pattern agaisnt an input string and
extract all of the capture groups. The function returns an id which
can be used with other functions to extract the information.
Functions related to strfind()
- getFindCount(id)
Returns the number of times that strfind() was able to match the input string.
id is the id returned by the strfind() function. - getGroupCount(id)
Returns the number of capture groups from strfind(). id is the id
returned by the strfind() function. - getGroup(id, matchNo, groupNo)
Returns the capture group groupNo for the match number specified by
matchNo. id is the id returned by the strfind() function. - getGroupStart(id, matchNo, groupNo)
Returns the start of capture group groupNo for the match number
specified by matchNo. id is the id returned by the strfind()
function. - getGroupEnd(id, matchNo, groupNo)
Returns the end of capture group groupNo for the match number
specified by matchNo. id is the id returned by the strfind()
function.