String Functions in DIAL
The following calc functions assess and manipulate strings in DIAL.
NOTE:The command-line interpreter on UNIX (the shell) treats multiple spaces as a single space. To preserve multiple spaces, use quotation marks around the argument.
Returns the integer value of the first character in the specified string, char. On EBCDIC platforms, returns the integer value in the EBCDIC collating sequence.
This function is the opposite of calc.chr(), which returns a character value for a specified integer.
For example, on an ASCII platform:
calc.ascii("A"); returns 65
calc.ascii("Foo"); returns 70
calc.ascii(" "); returns 32
Concatenates strings together. It takes a variable number of arguments and concatenates them. Numbers are interpreted as strings.
NOTE: In the following example, note the use of the \", \" to insert a comma and a blank space between the city and state, for example Allentown, PA.
For example:
calc.concat(Customer City,\", \",Customer State)
filename = concat("../temp/", Dimension[Sales Manager], ".pdf");
Returns a single-character string with the character represented by the number in the current character set, either ASCII or EBCDIC.
For example, on an ASCII platform:
calc.chr(65); returns A
calc.chr(32); returns a space
calc.chr(92); returns the left slash character (\)
Returns the starting position (index) in string of the string search_string. If string does not contain search_string, the function returns 0. This function is case-sensitive.
For example:
calc.index("New York, NY","n"); returns 0
calc.index("NewYork, NY","N"); returns 1
calc.index("New York, NY",","); returns 9
Determines the length of the specified string, string. Returns an integer.
Returns the string, string, with all uppercase alphabetical characters converted to lowercase.
Repeatedly pads the beginning of the specified string, string, with the specified fill characters, fill_string, until the result is num_chars characters long. If fill_string is omitted, spaces are assumed.
For example:
calc.lpad("foo", 5, "x"); returns xxfoo
calc.lpad("James", 10, "+-"); returns -+-+-James
calc.lpad("Long string", 5, "x"); returns Long string
calc.lpad("bar", 5); returns bar, preceded by two spaces
Returns the specified string, string, stripped of any characters in the trim_chars argument that appear at the beginning of the string. If trim_chars is omitted, the argument defaults to spaces.
For example:
calc.ltrim(" test"); returns test
calc.ltrim("xxxab", "x"); returns ab
calc.ltrim("* * **Hello", " *"); returns Hello
calc.ltrim("xxxab", "xab"); returns an empty string
Maps, that is, changes, any special characters in the specified string, string, to underscores (_). Any character that is not numeric, alphabetic, "-", ".","~", or "_" is mapped to "_". This function prevents creating invalid file names and paths.
For example:
calc.map_filename("mth**01"); returns mth__01
Replaces occurrences of the from_string in string with the to_string, adding or deleting characters as necessary.
For example:
calc.replace("We had an bogus time", "bogus", "excellent"); returns We had an excellent time
calc.replace("A|B|C", "|", "-"); returns A-B-C
calc.replace("We can merge words", " ", ""); returns Wecanmergewords
Returns the reversed contents of the specified string, string.
For example:
calc.reverse ("abc"); returns cba
Repeatedly pads the end of the specified string, string, with the string fill_string until the result is num_chars characters long. If fill_string is omitted, spaces are assumed.
For example:
calc.rpad("foo", 5, "x"); returns fooxx
calc.rpad("James", 10, "+-"); returns James+-+-+
calc.rpad("Long string", 5, "x"); returns Long string
calc.rpad("bar", 5); returns bar followed by two spaces
Returns the string, string, stripped of any characters in trim_chars that appear at the end of the string. If trim_chars is omitted, the argument defaults to spaces.
For example:
calc.rtrim("test "); returns test
calc.rtrim("abxxx", "x"); returns ab
calc.rtrim("Hello * -*", " -*"); returns Hello
calc.rtrim("xxxab", "xab"); returns an empty string
Parses the specified string, str, into separate segments based on the set of characters in the delimiters argument. Returns the segment indicated by token_num, with the first segment identified by 1. If delimiters is omitted, the argument defaults to spaces.
The function accepts negative segment numbers and interprets them as segments from the end of the string. For example, -1 indicates the last segment and -2 indicates the next-to-last segment. If the negative number identifies a segment before the first segment, the function returns a null string.
For example:
calc.scan("first, second, third", 2,","); returns second
calc.scan("first, second,,fourth",4,","); returns fourth
calc.scan("foo bar",4); returns a null string
calc.scan("foo bar",1); returns foo
calc.scan("foo|bar/baz",3,"|/"); returns baz
calc.scan("c:\\models\\data\\sales.mdl", 4, "\\"); returns sales.mdl
calc.scan("c:\\models\\data\\sales.mdl", 5, "\\"); returns a null string
calc.scan("c:/models/data/sales.mdl", 2, "/")); returns models
calc.scan("c:\\models\\data\\sales.mdl", -1, "\\"); returns sales.mdl
calc.scan("c:\\models\\data\\sales.mdl", -2, "\\"); returns data
calc.scan("c:\\models\\data\\sales.mdl", -4, "\\"); returns c:
calc.scan("c:\\models\\data\\sales.mdl", -5, "\\"); returns a null string
calc.scan("c:/models/data\\sales.mdl", -2, "/\\"); returns data
Separates a portion of a string from the entire string. The function accepts two or three arguments; start specifies at which character in the string to begin where the first character is 1, and length specifies how many characters from the starting position. The length argument is optional. If length is specified, up to that number of characters is returned. If length is not specified, the function returns all characters in string after the starting position. A negative starting position is assumed to be 1.
For example:
calc.substr("this is a test",2,5); returns his i
calc.substr("this is a test",3); returns is is a test
Translates characters in string that appear in from_chars with the character in the same position in to_chars. The function does not remove characters from a string.
For example:
calc.translate("Mary had a little lamb", " ", "x"); returns Maryxhadxaxlittlexlamb
calc.translate("able", "abcde", "bcdea"); returns bcla
calc.translate("Dimensional Insight", "DI", "d"); returns dimensional Insight
Returns the string string with all case characters converted to uppercase.
For example:
calc.upper("New York"); returns NEW YORK
Converts the specified string, value, to a number.