4

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.

2
  • 1
    Will the format always be the same. Why not use split? Commented Nov 9, 2010 at 13:32
  • yes the format will always be same Commented Nov 9, 2010 at 13:37

2 Answers 2

15

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
Sign up to request clarification or add additional context in comments.

1 Comment

index range for start?
6

If the string format will always be like that:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.