Common string operation functions in vbs

Time:2019-11-9

1. Split(expression, delimiter, count, compare)

Returns a 0-based one-dimensional array containing a specified number of substrings.
Expression: required. String expression, containing substrings and delimiters. If expression is a zero length string, split returns an empty array, that is, an array that does not contain elements and data.
Delimiter: optional. The character used to identify the bounds of a substring. If omitted, use a space (“”) as the separator. If the delimiter is a zero length string, a single element array containing the entire expression string is returned.
Count: optional. The number of substrings returned, – 1 indicates that all substrings are returned.
Compare: optional. The compare parameter can have the following values: 0 performs a binary comparison, 1 performs a text comparison, and 2 performs a comparison based on the information contained in the database in which the comparison is performed.

2. Replace(expression, find, replacewith, compare, count, start)

Returns a string in which a specified number of substrings are replaced by another substring.
Expression: required. String expression that contains the substring to replace.
Find: required. The substring being searched.
Replacewit: required. Substring to replace.
Start: optional. Where to start searching for substrings in expression. If omitted, the default is 1.
Count: optional. The number of substring substitutions performed. If omitted, the default value is – 1, indicating all possible replacements.
Compare: optional. The parameter value is the same as above.

3. Mid(string, start, length)

Returns the specified number of characters from a string.
String: a string expression from which characters are returned. Returns NULL if the string contains null.
Start: the start position of the extracted character part in string. If start exceeds the number of characters in string, mid returns a zero length string (”).
Length: the number of characters to return. If omitted or length exceeds the number of characters in the text, including the character at start, all characters in the string from start to the end of the string are returned.

4. LTrim(string), RTrim(string), Trim(string)

Returns a copy of a string without leading spaces (ltrim), trailing spaces (rtrim), or leading and trailing spaces (trim).
String: parameter is any valid string expression. Returns NULL if the string parameter contains null.

5. InStr(start, string1, string2, compare)

(InstrRev(start, string1, string2, compare))
Returns the position of a string from the header in another string
(returns where a string appears from the end of another string.).
Start: optional. A numeric expression that sets the start position of each search. If omitted, the search starts at the position of the first character. If start contains null, an error occurs. If compare is specified, you must have the start parameter.
String1: required. String expression that accepts the search.
String2: required. String expression to search for.
Compare: optional. The parameter value is the same as above.

6. String(number, character)

Returns a string of repeating characters of a specified length.
Number: returns the length of the string. Returns NULL if the number parameter contains null.
Character: Specifies the character code of the character or string expression, where the first character of the string expression is used to compose the returned string. Returns NULL if the character parameter contains null.

7. Space(number)

Returns a string consisting of a specified number of spaces.
Number: the parameter is the number of spaces required by the user in the string.

8. Left(string, length), Right(string, length)

Returns the specified number of characters from the left (right) side of the string.
String: a string expression whose leftmost (right) character is returned. Returns NULL if the string parameter contains null.
Length: a numeric expression indicating the number of characters to return. If it is 0, it returns a zero length string (“”); if it is greater than or equal to the total number of characters in the string parameter, it returns the entire string.

9. Len(string | varname)

Returns the number of characters in a string, or the number of bytes required to store a variable.
String: any valid string expression. Returns NULL if the string parameter contains null.
Varname: any valid variable name. Returns NULL if the Varname parameter contains null.

10. Asc(string)

Returns the ANSI character code corresponding to the first letter of the string.
String: parameter is any valid string expression. If the string parameter does not contain characters, a runtime error will occur.

11. Chr(charcode)

Returns the character corresponding to the specified ANSI character code.
Charcode: a parameter is a number that identifies a character. Numbers from 0 to 31 represent standard non printable ASCII code. For example, Chr (10) returns a line break.

12. LCase(string), UCase(string)

Returns the lowercase (upper case) form of the string, leaving all uppercase (lower case) and non alphabetic characters unchanged.
String: parameter is any valid string expression. Returns NULL if the string parameter contains null.

13. Join(list, delimiter)

Returns a string created by many substring joins contained in an array.
List: required. Contains a one-dimensional array of substrings to join.
Delimiter: optional. The character used to separate substrings in the return string. If omitted, a null character (”) will be used If the delimiter is a zero length string, all items are listed in the same list without a delimiter.

14. StrComp(string1, string2, compare)

Returns a value indicating the result of a string comparison. The strcomp function has the following return values: – 1, 0, 1, null.
String1, string2: required. Any valid string expression.
Compare: optional. The parameter value is the same as above.

15. StrReverse(string)

Returns a string in the reverse order of the specified string.
String: the parameter is the string to reverse the character. Returns a zero length string if the string is a zero length string (”). If string1 is null, an error occurs.