📜  VBA-字符串

📅  最后修改于: 2020-11-19 09:11:50             🧑  作者: Mango


字符串是一个字符序列,可以包含字母,数字,特殊字符或全部。如果变量用双引号“”引起来,则称该变量为字符串。

句法

variablename = "string"

例子

str1 = "string"   ' Only Alphabets
str2 = "132.45"   ' Only Numbers
str3 = "!@#$;*"  ' Only Special Characters
Str4 = "Asc23@#"  ' Has all the above

字符串函数

有预定义的VBA字符串函数,可帮助开发人员非常有效地使用字符串。以下是VBA支持的String方法。请单击每种方法以详细了解。

Sr.No. Function Name & Description
1 InStr

Returns the first occurrence of the specified substring. Search happens from the left to the right.

2 InstrRev

Returns the first occurrence of the specified substring. Search happens from the right to the left.

3 Lcase

Returns the lower case of the specified string.

4 Ucase

Returns the upper case of the specified string.

5 Left

Returns a specific number of characters from the left side of the string.

6 Right

Returns a specific number of characters from the right side of the string.

7 Mid

Returns a specific number of characters from a string based on the specified parameters.

8 Ltrim

Returns a string after removing the spaces on the left side of the specified string.

9 Rtrim

Returns a string after removing the spaces on the right side of the specified string.

10 Trim

Returns a string value after removing both the leading and the trailing blank spaces.

11 Len

Returns the length of the given string.

12 Replace

Returns a string after replacing a string with another string.

13 Space

Fills a string with the specified number of spaces.

14 StrComp

Returns an integer value after comparing the two specified strings.

15 String

Returns a string with a specified character for specified number of times.

16 StrReverse

Returns a string after reversing the sequence of the characters of the given string.