String Functions

substring

Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.

Arguments


Returns


Example

text as String
	text = "Hello World"
	display substring(text, first : 5)
The previous example displays "World!".

substring

Returns a new string that is a substring of this string. The substring begins at the specified first index and extends to the character at index last - 1. Thus, the length of the substring is last - first.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display substring(text, first : 5, last : 11)
	
The previous example displays "World".

fields

Given a source string and delimiter character, it returns an array of strings containing substrings of the original string delimited by the specified character. The delimiter is not included in the result.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display fields(text, delim : " ")
	
The example above displays ["Hello", "World!"].

length

Returns the number of characters in the string.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display length(text)
	
The previous example displays 12.

replace

Returns a new string with all the occurrences of from in the original string replaced by to.

This function has a variation that accepts a regular expression for matching the pattern to be replaced. See Regular Expressions for details.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display replace(text, from : "World", @to : "Mary")
	
The previous example displays "Hello Mary!".

charAt

This function returns the character contained in the specified index position.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display charAt(text, position : 6)
	
The previous example displays "W".

indexOf

Searches inside a string for another string and returns the index where the first occurrence happens.

This function has a variation that accepts a regular expression for matching. See Regular Expressions for details.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display indexOf(text, text : "Wor")
	
The previous example displays 6.

lastIndexOf

Searches inside a string for another string and returns the index where the last occurrence happens.

This function has a variation that accepts a regular expression for matching. See Regular Expressions for details.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display lastIndexOf(text, text : "o")
	
The previous example displays 7.

split

Splits a string using a regular expression. The delimiters are not included. See Regular Expressions for details.

Example

	text as String= "One Two Three"
	display split(text,'/\w+ \w+/m')
	
The previous example produces this output ["","Three"].

count

This function counts the number of times that a character is found in a string.

Arguments


Returns


Example

	date as String = "10/12/2004"
	if count (date, ch: "/") = 2 then
	   date = replace(date,"/","-")
	   display date
	else
	   display "Bad Date Format"
	end
	
The previous example displays "10-12-2004".

toUpperCase

Returns a new string with all the characters in uppercase.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display toUpperCase(text)
	
The previous example displays "HELLO WORLD!".

toLowerCase

Returns a new string with all the characters in lowercase.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display toLowerCase(text)
	
The previous example displays "hello world!".

trim

Returns a new string with all the whitespace removed from the beginning and the end of the string.

Arguments


Returns


Example

	option as String = " Yes   "
	if toLowerCase(trim (option))= "yes" then
	  display "The option is correct"
	else
	  display "The option is wrong".
	end
	
isMatch

Checks whether a string matches a regular expression. See Regular Expressions for details.

Example

	text as String= "One Two Three"
	display isMatch(text,'/\w+ Two \w+/g')
	
The previous example displays true.

contains

This function returns true if a substring in a text matches the specified regular expression. See Regular Expressions for details.

Example

	text as String= "One Two Three Four Five"
	display contains(text,'/\w+ Tw/g')
	
The previous example displays true.

chars

Returns an array of String(1) containing all the characters in the string.

Arguments


Returns


Example

	text as String= "fuego"
	characters as String(1)[]
	characters = chars(text)
	for each i in characters
	do
	    display "Char is "+ i
	end
	
	
The previous example displays:
	"Char is f"
	"Char is u"
	"Char is e"
	"Char is g"
	"Char is o"
	

pad

Returns a new string completed with spaces until the specified length is reached.

Arguments


Returns


Example

	text as String
	text = "Hello World!"
	display pad(text, len : 20)
	

strip

The strip function returns a new string truncated to a specified length. If the string is shorter than the length specified, it is left as it is.

Arguments


  • String: the string on which the function operates.
  • Int len: the desired length of the string. If you pass a negative number (e.g.: -1), it is ignored and returns an empty string.

Returns


  • String: a new string of the specified length.

Example

	text as String
	text = "Hello World!"
	display strip(text, len : 5)
	
The previous example displays "Hello".

How to convert a String to a Time

The following will convert the string in strDate into a Time value to be set in realDate.
strDate = "Tue Feb 22 15:26:02 ART 2005"
strPattern = "EEE MMM dd HH:mm:ss z yyyy"
	
simpleDateFormat = Java.Text.SimpleDateFormat(strPattern)
realDate = parse(simpleDateFormat, strDate)
	
display realDate

The value of realDate becomes 2005-02-22 15:26:02-03

realDate is a variable of type Time. It contains the same date that was expressed as a string in strDate.