如何在VBScript中截取文本

4

我正在使用VBScript

我得到了以下文本

str = "tcm:1-245-9"

现在我想以这样的方式子串上面的字符串,从而获得以下输出:

pstr = "245"

请仅用VBScript提供建议。

谢谢。


1
格式会一直保持不变吗?为什么不使用分割函数(split)呢? - Ash Burlaczenko
是的,格式将始终保持不变。 - Manoj Singh
2个回答

15
你可以使用

标签。

Mid(string,start[,length]) 

string - Required. The string expression from which characters are returned

start  - Required. Specifies the starting position. If set to greater than the number of characters in string, it returns an empty string ("")

length  - Optional. The number of characters to return
或者使用。
Split(expression[,delimiter[,count[,compare]]]) 

expression - Required. A string expression that contains substrings and delimiters

delimiter  - Optional. A string character used to identify substring limits. Default is the space character

count      - Optional. The number of substrings to be returned. -1 indicates that all substrings are returned

compare    - Optional. Specifies the string comparison to use.

            Can have one of the following values:
              * 0 = vbBinaryCompare - Perform a binary comparison
              * 1 = vbTextCompare - Perform a textual comparison

起始的索引范围是什么? - Sam Ginrich

6
如果字符串格式永远都是这样的:
segments = Split(str,"-")
pstr = segments(1)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接