Manoj Singh
Manoj Singh

Reputation: 7707

how to substring text in vbscript

I am using VBScript

I have got below text

str = "tcm:1-245-9"

Now I want to substring above string in such a way, so that I get the output as below

pstr = "245" from the above string,

Please let me know suggestions in VBScript only.

Thanks.

Upvotes: 4

Views: 58835

Answers (2)

Kangkan
Kangkan

Reputation: 15571

You can use

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

or use

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

Upvotes: 15

Mark Bell
Mark Bell

Reputation: 29735

If the string format will always be like that:

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

Upvotes: 6

Related Questions