Does VBScript have a substring() function?

StringVbscript

String Problem Overview


Is there a substring() function in VBScript similar to Java's string.substring()?

String Solutions


Solution 1 - String

Yes, Mid.

Dim sub_str
sub_str = Mid(source_str, 10, 5)

The first parameter is the source string, the second is the start index, and the third is the length.

@bobobobo: Note that VBScript strings are 1-based, not 0-based. Passing 0 as an argument to Mid results in "invalid procedure call or argument Mid".

Solution 2 - String

As Tmdean correctly pointed out you can use the Mid() function. The MSDN Library also has a great reference section on VBScript which you can find here:

> VBScript Language Reference (MSDN Library)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCarlos BlancoView Question on Stackoverflow
Solution 1 - StringTmdeanView Answer on Stackoverflow
Solution 2 - StringKevView Answer on Stackoverflow