Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to substring text in vbscript

Tags:

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.

like image 860
Manoj Singh Avatar asked Nov 30 '22 17:11

Manoj Singh


2 Answers

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
like image 82
Kangkan Avatar answered Dec 05 '22 07:12

Kangkan


If the string format will always be like that:

segments = Split(str,"-")
pstr = segments(1)
like image 26
Mark Bell Avatar answered Dec 05 '22 06:12

Mark Bell