2010-11-09 62 views
4

我使用VBScript如何串文字在VBScript

我有如下文字

str = "tcm:1-245-9" 

現在我想串上面的字符串以這樣的方式,所以我得到的輸出如下

pstr = "245"從上面的字符串,

請讓我知道在VBScript的建議只。

謝謝。

+1

將格式始終是相同的。爲什麼不使用拆分? – 2010-11-09 13:32:43

+0

是的格式將永遠是相同的 – 2010-11-09 13:37:00

回答

6

如果字符串格式將永遠是這樣的:

segments = Split(str,"-") 
pstr = segments(1) 
+0

許多謝謝@Mark – 2010-11-09 13:52:01

+0

沒問題,很樂意提供幫助。 – 2010-11-09 15:17:12

14

您可以使用

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