Skip to content

Commit

Permalink
restrict substring to string size
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneu committed May 8, 2019
1 parent 01d4639 commit 33a32ae
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Modules/StringExtensions.bas
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ End Function


Public Function Substring(ByVal text As String, startIndex As Integer, Optional length As Variant) As String
If IsMissing(length) Or TypeName(length) <> "Integer" Then
If startIndex > Len(text) Then
startIndex = Len(text)
End If

If IsMissing(length) Or TypeName(length) <> "Integer" Or length > Len(text) Then
length = Len(text) - startIndex
End If

Expand Down

0 comments on commit 33a32ae

Please sign in to comment.