String Functions¶
- Format
- FormatMessage
- HashString
- InStr
- InStrRev
- LCase
- Left
- Len
- LTrim
- Trim
- Mid
- Replace
- Right
- RTrim
- Space
- StrComp
- String
- StringLike
- StrReverse
- TitleCase
- UCase
Format¶
Description
Returns a string formatted according to a format string.
Syntax
Arguments
- expression
- Any valid expression.
- style
- Optional. A valid named or user-defined format String expression.
Microsoft's own guide to the format function covers the named and user-defined formats in full: https://support.office.com/en-us/article/Format-Function-6F29D87B-8761-408D-81D3-63B9CD842530
Example
MyStr = Format(Time, "Long Time")
' Returns current system date in the system-defined long date format.
FormatMessage¶
Description
Builds a string from a message with numbered parameters and the values to put in them.
It is useful for building messages for WriteToLog or the Lookup Function, and anywhere else you need to build a string dynamically.
Syntax
Arguments
- Message
- The message to format. Write each parameter as
%followed by its number: the first is%1, the second%2and so on.
- The message to format. Write each parameter as
- values
- The value(s) to replace the parameters within the message.
- A single value or an array of values.
HashString¶
Description
Calculates a hash of one or more strings.
Syntax
Arguments
- hashMethod
- The hash method:
md5,sha1,sha256,sha384orsha512.
- The hash method:
- strings
- The strings to hash. If you pass several, HashString returns a hash of the strings concatenated.
InStr¶
Description
Returns the position of the first occurrence of a string in another string.
Syntax
Arguments
- start
- Optional. The position to start the search at. If omitted, the search starts at position 1.
- string_being_searched
- The string to search.
- string2
- The string to search for.
- compare
- Optional. The type of comparison to perform. The valid choices are:
| Value | Explanation |
|---|---|
| 0 | Binary comparison. |
| 1 | Textual comparison. |
InStrRev¶
Description
Returns the position of the first occurrence of a string in another string, starting from the end of the string.
Syntax
Arguments
- string_being_searched
- The string to search.
- string2
- The string to search for.
- start
- Optional. The position to start the search at. If omitted, the search starts at position -1, the last character.
- compare
- Optional. The type of comparison to perform. The valid choices are:
| Value | Explanation |
|---|---|
| 0 | Binary comparison. |
| 1 | Textual comparison. |
LCase¶
Description
Converts a string to lower case.
Syntax
Arguments
- text
- The string to convert to lower case.
Left¶
Description
Returns a substring from a string, starting from the left-most character.
Syntax
Arguments
- text
- The string to extract from.
- number_of_characters
- The number of characters to extract, starting from the left-most character.
Len¶
Description
Returns the length of a string.
Syntax
Arguments
- text
- The string to return the length for.
LTrim¶
Description
Removes leading spaces from a string.
Syntax
Arguments
- text
- The string to remove leading spaces from.
Trim¶
Description
Returns a text value with the leading and trailing spaces removed.
Syntax
Arguments
- text
- The text value to remove the leading and trailing spaces from.
Mid¶
Description
Extracts a substring from a string, starting at any position.
Syntax
Arguments
- text
- The string to extract from.
- start_position
- The position to start extracting from. The first position in the string is 1.
- number_of_characters
- The number of characters to extract.
Replace¶
Description
Replaces a sequence of characters in a string with another set of characters.
Syntax
Arguments
- string
- The string to search.
- find
- The part of the string to replace.
- replacewith
- The replacement substring.
- start
- Optional. The position in string to start replacing characters at.
- count
- Optional. The number of substitutions to make.
The default, -1, makes every possible substitution.
- Optional. The number of substitutions to make.
- compare
- Optional. A number for the kind of comparison to use. If omitted, the function performs a binary comparison. The valid choices are:
| Value | Explanation |
|---|---|
| 0 | Binary comparison. |
| 1 | Textual comparison. |
Right¶
Description
Extracts a substring from a string starting from the right-most character.
Syntax
Arguments
- text
- The string to extract from.
- number_of_characters
- The number of characters to extract, starting from the right-most character.
RTrim¶
Description
Removes trailing spaces from a string.
Syntax
Arguments
- text
- The string to remove trailing spaces from.
Space¶
Description
Returns a string with a specified number of spaces.
Syntax
Arguments
- number
- The number of spaces to return.
StrComp¶
Description
Returns the result of a string comparison as a number.
Syntax
Arguments
- string1
- Any valid string expression.
- string2
- Any valid string expression.
- compare
- Optional. A number for the kind of comparison to use. If omitted, the function performs a binary comparison. The valid choices are:
| Value | Explanation |
|---|---|
| 0 | Binary comparison. |
| 1 | Textual comparison. |
String¶
Description
Returns a string of one character repeated to a given length.
Syntax
Arguments
- number
- The length of the returned string. If number contains Null, String returns Null.
- character
- A character code, or a string whose first character String repeats. If character contains Null, String returns Null. If character is a number greater than 255, String converts it to a valid character code using modulus 256.
StringLike¶
Description
Compares a string against a pattern. It returns True if string matches pattern, and False if it does not. If both string and pattern are empty strings, it returns True.
Syntax
Arguments
- string
- A string expression.
- pattern
- The pattern to compare the string to.
- The comparison is case-sensitive, and the whole of string must match the pattern. It is not a "contains" or "starts with" test. The following table shows the characters allowed in pattern and what they match.
| Characters in pattern | Matches in string |
|---|---|
| ? | Any single character |
| * | Zero or more characters |
| Any other character | Itself. Only ? and * have a special meaning; the # and [charlist] wildcards of VBScript's Like operator are not supported and match literally. |
Example
' IMan-specific. The pattern is the SECOND argument.
' Only * (any run of characters) and ? (exactly one) are
' supported -- not the # or [charlist] of VBScript's
' Like operator -- and it is case-sensitive. The whole
' value must match, so the pattern is implicitly
' anchored.
StringLike(%ItemCode, "ACME-*") ' "ACME-4471-BLU" returns True
StringLike(%ItemCode, "ACME-????-*") ' "ACME-4471-BLU" returns True
StringLike(%ItemCode, "acme-*") ' Returns False -- case matters
StringLike(%ItemCode, "ACME") ' Returns False -- not a prefix test
StrReverse¶
Description
Returns a string with its characters in reverse order.
Syntax
Arguments
- string
- The string to reverse. If string is a zero-length string (""), StrReverse returns a zero-length string. If string is Null, an error occurs.
TitleCase¶
Description
Returns a string with the first letter of every word in upper case and every other character in lower case.
Syntax
Arguments
- string
- The string to format.
UCase¶
Description
Converts a string to upper case.
Syntax
Arguments
- text
- The string to convert to upper case.