String Helper

The String Helper file contains methods that assist in working with strings.

Loading this Helper

This helper is loaded using the following code:

loadHelper "string"

The following methods are available:

randomString()

Generates a random string based on the type and length you specify. Useful for creating passwords or generating random hashes.

The first parameter specifies the type of string, the second parameter specifies the length. The following choices are available:

Usage example:

put randomString("alnum", 16) into tRandomString

alternator()

Allows two or more items to be alternated between, when cycling through a loop. Example:

resetAlternator
repeat with i = 1 to 10
    put alternator("string one", "string two") after tAlternated
end repeat

Note: To use multiple separate calls to this function call the resetAlternator handler first.

You can add as many parameters as you want, and with each iteration of your loop the next item will be returned.

resetAlternator
repeat with i = 1 to 10
    put alternator("one", "two", "three", "four", "five") after tAlternated
end repeat

repeater()

Generates repeating copies of the data you submit. Example:

put return into tString
put repeater(tString, 30) into tRepeaatedString

The above would generate 30 newlines.

reduceDoubleSlashes()

Converts double slashes in a string to a single slash, except those found in http://. Example:

put "http://example.com//index.irev" into tString
put reduceDoubleSlashes(tString) into tString -- results in "http://example.com/index.irev"

trimSlashes()

Removes any leading/trailing slashes from a string. Example:

put "/this/that/theother/" into tString
put trimSlashes(tString) into tString -- results in this/that/theother

reduceMultiples()

Reduces multiple instances of a particular character occuring directly after each other. Example:

put "Fred, Bill,, Joe, Jimmy" into tString
put reduceMultiples(tString,",") into tString -- results in "Fred, Bill, Joe, Jimmy"

The function accepts the following parameters:

reduceMultiples(string: text to search in, string: character to reduce, boolean: whether to remove the character from the front and end of the string) The first parameter contains the string in which you want to reduce the multiplies. The second parameter contains the character you want to have reduced. The third parameter is FALSE by default; if set to TRUE it will remove occurences of the character at the beginning and the end of the string. Example: put ",Fred, Bill,, Joe, Jimmy," into tString
put reduceMultiples(tString, ",", TRUE) into tString -- results in "Fred, Bill, Joe, Jimmy"

quotesToEntities()

Converts single and double quotes in a string to the corresponding HTML entities. Example:

put "Joe's" && quote & "dinner" & quote into tString
put quotesToEntities(tString) into tString -- results in "Joe's "dinner""

stripQuotes()

Removes single and double quotes from a string. Example:

put "Joe's" && quote & "dinner" & quote into tString
put stripQuotes(tString) into tString -- results in "Joes dinner"