In This Topic
The text functions allow you to manipulate text strings in various ways, such as conversions to other data types, formatting and searching. Note that to quickly concatenate (join) two or more strings, you can use the + (plus) or & (ampersand) Operators. See the document on Data Types for information on how strings are converted to numbers (and vice-versa) as required automatically.
Asc |
Returns the ASCII code for a specified character |
Syntax |
Asc (char) |
Inputs |
Char is a string with a single character in it. If it has more than one, the first character is used |
Notes |
Code and this function is the exact opposite of Char |
Examples |
Asc ("Q") = 81 |
See Also |
Char |
Char |
Returns the character with the specified ASCII code |
Syntax |
Char (code) |
Inputs |
Code is an ASCII code between 0 and 255. If code is more than 255, code mod 256 is used |
Notes |
Chr and this function is the exact opposite of Asc |
Examples |
Char (81) = "Q" |
See Also |
Asc |
Concatenate |
Joins two or more strings together and returns the resulting string |
Syntax |
Concatenate (string1, string2, ...) |
Inputs |
String1, string2, ... are the strings (or any expressions that evaluate to strings) to be joined, you can provide several |
Notes |
A simpler way to concatenate strings is to use the & (ampersand) or + (plus) operators, eg "string1" & "string2" |
Examples |
Concatenate ("built", " using ", "concatenate") = "built using concatenate" |
Dollar |
Returns an expression formatted as a dollar amount |
Syntax |
Dollar (val) |
Inputs |
Val is any numerical value |
Examples |
Dollar (5 * 3) = $15.00 |
See Also |
DollarNoUnit |
DollarNoUnit |
Returns an expression formatted as a dollar amount without the $ (dollar sign) |
Syntax |
DollarNoUnit (val) |
Inputs |
Val is any numerical value |
Examples |
DollarNoUnit ("3 + 2") = 5.00 |
See Also |
Dollar |
Exact |
Compares two values as strings |
Syntax |
Exact (string1, string2) |
Inputs |
String1, string2 are the two text strings to compare |
Outputs |
Returns Yes if both values are exactly the same, No otherwise |
Notes |
This function is case sensitive |
Examples |
Exact ("a string", "A String") = No |
Field |
Extracts a particular substring from a separated string |
Syntax |
Field (string, index, separator) |
Inputs |
String is a list of strings separated by a certain character. Index is the position of the desired substring within string. separator is optional, and is a single character which separates the substrings. The default is | (pipe) |
Notes |
If index is out of range, an empty string is returned |
Examples |
Field ("red|green|blue", 2) = "green" Field ("$34.20;45mm;340mm;2.5hr", 3, ";") = 340mm |
See Also |
FieldCount |
FieldCount |
Calculates the number of fields in a separated string |
Syntax |
FieldCount (string, separator) |
Inputs |
String is a list of strings separated by a certain character, separator. If separator is omitted, the default of | (pipe) is used |
Notes |
If separator is not found in string, the result is 1 (unless string is empty) |
Examples |
FieldCount ("red|green|blue") = 3 FieldCount ("$34.20;45mm;340mm;2.5hr", ";") = 4 |
See Also |
Field |
Find |
Locates a specified substring within a given string |
Syntax |
Find (target, source, start) |
Inputs |
Target is a string which is looked for within the source string. If the optional parameter start is provided, the function will start looking at that position |
Outputs |
The position in source where target was found, or 0 if it is not found |
Notes |
Find is case-sensitive |
Examples |
Find ("is", "This is a string") = 3 Find ("is", "This is a string", 4) = 6 |
See Also |
InStr, Search |
FindOneOf |
Searches a string for one of a set of characters |
Syntax |
FindOneOf (chars, source, start) |
Inputs |
Chars is a list of characters as a string, which is looked for within the source string. If the optional parameter start is provided, the function will start looking at that position |
Outputs |
The position in source where one of the characters in chars was found, or 0 if none of them are found |
Examples |
FindOneOf ("rh", "This is a string") = 2 FindOneOf ("rh", "This is a string", 5) = 13 |
InStr |
Locates a specified substring within a given string |
Syntax |
InStr (start, source, target) |
Inputs |
Target is a string which is looked for within the source string. If the optional parameter start is provided, the function will start looking at that position |
Outputs |
The position in source where target was found, or 0 if it is not found |
Notes |
This function operates exactly the same as Find, except with the parameters in a different order |
Examples |
InStr ("This is a string", "is") = 3 InStr (4, "This is a string", "is") = 6 |
See Also |
Find, Search |
LCase |
Converts a given string to lower case |
Syntax |
LCase (string) |
Inputs |
String is what needs to be converted to lower case |
Notes |
Lower has the same functionality. Any characters that are not upper-case letters are not affected |
Examples |
LCase ("This Is A String") = "this is a string" |
See Also |
UCase, LowerNoCvt, UpperNoCvt |
Left |
Returns a certain number of characters from the start of a string |
Syntax |
Left (string, count) |
Inputs |
String is what to get the left hand characters of. Count is optional, and determines how many characters to return (default is 1) |
Notes |
If count is more than the length of string, the whole string is returned |
Examples |
Left ("This is a string") = "T" Left ("This is a string", 6) = "This i" |
See Also |
Mid, Right |
Len |
Returns the length of a string |
Syntax |
Len (string) |
Inputs |
String is what to find the length of |
Notes |
The result includes spaces and all other characters |
Examples |
Len ("This is a string") = 16 Len (Empty) = 0 |
Length |
Converts a specific value to a length in the current units |
Syntax |
Length (value, precision) |
Inputs |
Value is any expression which gives a numerical result. Precision is optional, and is the number of decimal places (if positive) or the largest denominator to use (if negative) |
Outputs |
The unit used on the returned value is that specified on the File Options dialog |
Notes |
If precision is included and is not negative, the result is rounded to that number of decimal places. Otherwise, the result is written with fractions, with precision as the largest denominator. See the examples for a demonstration. To find the length of a string, use the Len function instead |
Examples |
Assuming default units is set to mm: Length (4' + 8") = 1422.4mm Length (63mm, 3) = 63.000mm Length (4.128mm, -8) = 4 1/8mm |
See Also |
LengthNoUnit |
LengthNoUnit |
This is the same as the Length function but the units text is not added |
Syntax |
LengthNoUnit (value, precision) |
Inputs |
Value is any expression which gives a numerical result. Precision is optional, and is the number of decimal places (if positive) or the largest denominator to use (if negative) |
Notes |
See the notes on Length for information about precision |
Examples |
Assuming default units is set to mm: LengthNoUnit (4' + 8") = 1422.4 LengthNoUnit (87.321cm, -9) = 873 2/9 |
See Also |
Length |
LowerNoCvt |
Converts a given string to lower case |
Syntax |
LowerNoCvt (string) |
Inputs |
String is what needs to be converted to lower case |
Notes |
Any value which is not a string (Such as a measurement) will not be effected. See the list of Data Types.
Any characters that are not upper-case letters are not affected. |
Examples |
LowerNoCvt ("This Is A String") = "this is a string" |
See Also |
UpperNoCvt, LCase, UCase |
LTrim |
Removes all the white space from the start of a specified string |
Syntax |
LTrim (text) |
Inputs |
Text is the string to strip the white space from |
Examples |
LTrim (" string with spaces ") = "string with spaces " |
See Also |
RTrim, Trim |
Mid |
Returns a certain number of characters from the middle of a string |
Syntax |
Mid (string, start, count) |
Inputs |
String is what to extract the substring from. Start is the position in the string where the substring begins. Count is optional, and determines how many characters to return. If it is omitted, the substring from start to the end of string is returned |
Examples |
Mid ("This is a string", 6, 8) = "is a str" Mid ("This is a string", 13) = "ring" |
See Also |
Left, Right |
Replace |
Inserts a new string in place of a specified substring |
Syntax |
Replace (string, start, count, newStr) |
Inputs |
String, start and count operate in exactly the same way as with the Mid function, and are used to specify the substring to be replaced. NewStr is the text that will be inserted in the place of the substring |
Outputs |
Returns a copy of the whole input string, except with a section of it replaced by newStr |
Notes |
As opposed to the third parameter in the Mid function, count is not optional. The length of newStr does not have to be equal to count, which means you could for example replace several characters with only one |
Examples |
Replace ("This is a string", 9, 1, "one example ") = "This is one example string") |
See Also |
Substitute |
Rept |
Repeats a string a specified number of times |
Syntax |
Rept (string, count) |
Inputs |
String is what will be repeated count times |
Examples |
Rept ("Xo", 4) = "XoXoXoXo" |
Right |
Returns a certain number of characters from the end of a string |
Syntax |
Right (string, count) |
Inputs |
String is what to get the right hand characters of. Count is optional, and determines how many characters to return (default is 1) |
Notes |
If count is more than the length of string, the whole string is returned |
Examples |
Right ("This is a string") = "g" Right ("This is a string", 5) = "tring" |
See Also |
Left, Mid |
RTrim |
Removes all the white space from the end of a specified string |
Syntax |
RTrim (text) |
Inputs |
Text is the string to strip the white space from |
Examples |
RTrim (" string with spaces ") = " string with spaces" |
See Also |
LTrim, Trim |
Search |
Locates a specified substring within a given string |
Syntax |
Search (target, source, start) |
Inputs |
Target is a string which is looked for within the source string. If the optional parameter start is provided, the function will start looking at that position |
Outputs |
The position in source where target was found, or 0 if it is not found |
Notes |
Search is exactly the same as the Find function, except that it is case-insensitive (it doesn't distinguish between upper and lower case letters) |
Examples |
Search ("IS", "This is a string") = 3 Search ("Is", "This is a string", 4) = 6 |
See Also |
Find, InStr |
StringToArray |
Converts a string of separated items into an array |
Syntax |
StringToArray (string, separator) |
Inputs |
String is a list of elements separated by a certain character or set of characters. Separator is optional, and is the string found between the elements. The default is "|" (the pipe character) |
Notes |
This function is effectively the opposite of ArrayToString |
Examples |
StringToArray ("$3.40 260mm $1.90", " ") = ["$3.40","260mm","$1.90"] |
See Also |
ArrayToString |
Substitute |
Replaces all occurrences of a substring with a specified string |
Syntax |
Substitute (string, oldStr, newStr, count) |
Inputs |
String is what to make the substitutions to. It is searched for all occurrences of oldStr which are replaced by newStr. Count is optional, and is the maximum number of replacements to make |
Outputs |
Returns a copy of the whole input string, with newStr substituted for any occurrences of oldStr |
Notes |
This function can be used for simple variable replacement in strings, as illustrated in the example. It is case-sensitive |
Examples |
Substitute ("Hello $name$", "$name$", "Joe") = "Hello Joe" |
See Also |
Replace |
Text |
Explicitly converts any value to a text string |
Syntax |
Text (value) |
Inputs |
Value is a variable of any type |
Outputs |
Converts values to the base unit, see TextNoUnit for details |
Notes |
Values are usually converted to strings automatically as required. A situation where the Text function would be useful is when joining variables of unknown type as strings |
Examples |
If X = 5 and Y = 3, then X + Y = 8, but Text (X) + Text (Y) = "53" |
See Also |
TextNoUnit |
TextNoUnit |
Converts a variable of any type to a string, but does not include any units |
Syntax |
TextNoUnit (value) |
Inputs |
Value is a variable of any type |
Outputs |
Values are converted to the base measurement first, eg all times convert to minutes, prices to dollars, and any length to your specified Length Units |
Notes |
See the notes on the Text function |
Examples |
TextNoUnit (75 cents) = 0.75 TextNoUnit (1.5 hours) = 90 |
See Also |
Text |
Trim |
Removes all the white space from the start and end of a specified string |
Syntax |
Trim (text) |
Inputs |
Text is the string to strip the white space from |
Examples |
Trim (" string with spaces ") = "string with spaces" |
See Also |
LTrim, RTrim |
UCase |
Converts a given string to upper case |
Syntax |
UCase (string) |
Inputs |
String is what needs to be converted to upper case |
Notes |
Upper has the same functionality. Any characters that are not lower-case letters are not affected |
Examples |
UCase ("This Is A String") = "THIS IS A STRING" |
See Also |
LCase, UpperNoCvt, LowerNoCvt |
UpperNoCvt |
Converts a given string to upper case |
Syntax |
UpperNoCvt (string) |
Inputs |
String is what needs to be converted to upper case |
Notes |
Any value which is not a string (Such as a measurement) will not be effected. See the list of Data Types.
Any characters that are not lower-case letters are not affected. |
Examples |
UpperNoCvt ("This Is A String") = "THIS IS A STRING" UpperNoCvt ("15mm") = "15mm" |
See Also |
UpperNoCvt, LCase, UCase |
Value |
Converts a string into a numerical value |
Syntax |
Value (text) |
Inputs |
Text is a string that contains a number |
Outputs |
Values are converted to a base unit, see TextNoUnit for details |
Notes |
If the string contains any text apart from units (eg "dollars") an error occurs |
Examples |
Value ("0.5 hours") = 30.00mn Value ("30 cents plus $4") = $4.30 |