Sub Mid($s As String, $startPos As Integer, $length As Integer) As String

' -or-

Sub Copy($s As String, $startPos As Integer, $length As Integer) As String


Mid returns a substring containing $length characters, starting at position $startPos. The first character of $s has the index 1.


If $startPos is greater than the length of $s, Mid returns an empty string.


If $length specifies more characters than are available, only the characters from position $startPos to the end of $s are returned.


Parameters


  • $s ... String expression from which characters are returned.
  • $startPos ... Integer expression. Starting position of the characters to return. $startPos is one-based.
  • $length ... Integer expression. Number of characters to return.


Example:

Dim $s, $s2

$s = "This is a text"
$s2 = Mid($s, 6, 2)
' returns $s2 = "is"