Left 函数(Right函数就是从右边开始算起)
返回指定数目的从字符串的左边算起的字符。Left(string, length) 参数 string:字符串表达式,其最左边的字符被返回。如果 string 参数中包含 Null,则返回 Null。 Length:数值表达式,指明要返回的字符数目。如果是 0,返回零长度字符串 ("");如果大于或等于 string 参数中的字符总数,则返回整个字符串。 例子: Dim MyString, LeftString MyString = "VBscrīpt" LeftString = Left(MyString, 3) ' LeftString contains "VBS". *********************************** Mid 函数 从字符串中返回指定数目的字符。 Mid(string, start[, length]) 参数: string:字符串表达式,从中返回字符。如果 string 包含 Null,则返回 Null。 Start:string 中被提取的字符部分的开始位置。如果 start 超过了 string 中字符的数目,Mid 将返回零长度字符串 ("")。 Length:要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到字符串结束的所有字符。 例子 Dim MyVar MyVar = Mid("VB scrīpt is fun!", 4, 6) ' MyVar contains "scrīpt". ******************** InStr函数(InStrRev函数相反从最后向前起) 返回指定的字符串在另一字符串中最先出现的位置。 InStr([start, ]string1, string2[, compare]) 参数: start:起始位置,默认从第一位 string1:主体字符串,从左向右查找。如果string1为 Null,则返回 Null。 string2:查找的字符串,如果string2为 Null,则返回 Null。找不到就返回0。 compare:0是二进制比较,1是文本比较。0为缺省值。个人感觉区别就是在大小写。 例子 Dim SearchString, SearchChar, MyPos SearchString ="XXpXXpXXPXXP" ' String to search in. SearchChar = "P" ' Search for "P". MyPos = Instr(4, SearchString, SearchChar, 1) ' A textual comparison starting at position 4. Returns 6. MyPos = Instr(1, SearchString, SearchChar, 0) ' A binary comparison starting at position 1. Returns 9. MyPos = Instr(SearchString, SearchChar) ' Comparison is binary by default (last argument is omitted). Returns 9. MyPos = Instr(1, SearchString, "W") ' A binary comparison starting at position 1. Returns 0 ("W" is not found). ****************** Split 函数 在指定的 delimiter 参数出现的所有位置断开 String 对象,将其拆分为子字符串,然后以数组形式返回子字符串。 Split(expression[, delimiter[, count[, compare]]]) 参数 expression:主体字符串,也就是要被拆分处的字符或字符串。 delimiter:拆分元素,默认是(" ") count:Number [可选] 要放入数组中的项目数。 compare:0是二进制比较,1是文本比较。0为缺省值。 例子 Dim MyString, MyArray, Msg MyString = "VBscrīptXisXfun!" MyArray = Split(MyString, "x", -1, 1) ' MyArray(0) contains "VBscrīpt". ' MyArray(1) contains "is". ' MyArray(2) contains "fun!". Msg = MyArray(0) & " " & MyArray(1) Msg = Msg & " " & MyArray(2) MsgBox Msg |
|