VBScript的字符串方法
方法 | 描述 | 传参示例 | 结果 |
---|---|---|---|
Asc(string) | 返回第一个字符的ASCII码,相当于JS的String.charCodeAt | "Alpha" | 65 |
Chr(charcode) | 返回对应的字母,相当于JS的String.fromCharCode | 65 | A |
CStr(expression) | 把表达式转换为字符串类型 | 5+5 | 10 |
InStr([start,]string,substring) | 可返回substring在string中首次出现的位置。相当于JS的indexOf | "Two words","w" 3,"Two words","w" |
2 5 |
InStrRev(string,substring[,start]) | 返回substring在string中首次出现的位置。搜索从字符串的末端开始,但是返回的位置是从字符串的起点开始计数的,相当于JS的lastIndexOf。 | "1234567890123","3" "1234567890123","3",5 |
13 3 |
Join(stringarray[,delimter]) | 将一个字符串数组转换为数组,delimter为分隔符,默认是空格字符,相当于JS中的数组方法join. | Array("one","two","three") Array("one","two","three"),"*" |
one two three one*two*three |
LCase(string) | 把指定的字符串转换为小写。相当于JS的toLowerCase | "LOWERCASE" | lowercase |
Left(string,number) | 从字符串的左侧返回指定数目的字符,有点像JS的substr方法 | "Left Nine Characters.",9 | Left Nine |
Len(string) | 返回字符串的长度 | "This string is 34 characters long." | 34 |
LTrim(string) | 除去字符串开始的空格,就是firefox的trimLeft方法 | " No leading spaces." | No leading spaces. |
Mid(string,start[,length]) | 从字符串中返回指定数目的字符,用法与JS的slice差不多 | "This is the middle of the string.",13 "This is the middle of the string.",13,6 |
middle of the string. middle |
Replace(string,a,b) | 将字符串string中的a子串全部替换为b子串,与JS的replace方法差不多 | "These characters are the Right Ten.",10 | Right Ten. |
RTrim(string) | 去掉右边的空白,就是firefox的trimRight方法 | "No trailing spaces. " | No trailing spaces. |
Space(number) | 返回由指定数目的空格组成的字符串 | 10 | |
Split(string[,delimter]) | 用分隔符切割实际字符串为数组,默认是一个格的空白字符. | "How now brown cow?" "How now, brown cow?","," |
Array("How","now","brown","cow?") Array("How now"," brown cow?") |
StrComp(string1,string2) | 比较两个字符串,并返回表示比较结果的一个值,返回1,0,-1,1表示大于 | "beta","alpha" "alpha","alpha" "alpha","beta" |
1 0 -1 |
StrReverse(string) | 反转一个字符串 | ".redro esrever ni gnirts tupni eht si sihT" | This is the input string in reverse order. |
String(number,charcode) | 返回包含指定长度的重复字符的一个字符串 | 10,65 | AAAAAAAAAA |
Trim(string) | 去掉两端的空白,就是JS的trim方法 | " No leading or trailing spaces. " | No leading or trailing spaces. |
UCase(string) | 将所有字母大写化,相当于JS的toUpperCase. | "uppercase" | UPPERCASE |