Cuts a string from a string starting from a specific character index and until a specific character index.
Edit 2024-02-28: Adding error catching for some strange scenario at end.
Edit: 2024-04-03: Fix issue when Start1 is less than 0
Function CutString1(CutFrom, Optional Start1 = 1, Optional End1 = 1) As String
' Cuts a string from a string starting from a specific character index and until a specific character index
' Start1 is no to cut from (included)
' End1 is no to stop cut to (included)
' CutFrom is the string to cut from
' If Start1 is not given, it will be assumed as 1
' If End1 is not given, it will be assumed as the length of the string.
Dim St1, En1
CutString1 = ""
St1 = 1
If Start1 < Len(CutFrom) And Start1 > 0 Then St1 = Start1
En1 = Len(CutFrom) + 1
If End1 = 1 Then GoTo Step3
If End1 < Len(CutFrom) Then En1 = End1 + 1
Step3:
If St1 > 0 Then CutString1 = Mid(CutFrom, St1, En1 - St1)
End Function
' Cuts a string from a string starting from a specific character index and until a specific character index
' Start1 is no to cut from (included)
' End1 is no to stop cut to (included)
' CutFrom is the string to cut from
' If Start1 is not given, it will be assumed as 1
' If End1 is not given, it will be assumed as the length of the string.
Dim St1, En1
CutString1 = ""
St1 = 1
If Start1 < Len(CutFrom) And Start1 > 0 Then St1 = Start1
En1 = Len(CutFrom) + 1
If End1 = 1 Then GoTo Step3
If End1 < Len(CutFrom) Then En1 = End1 + 1
Step3:
If St1 > 0 Then CutString1 = Mid(CutFrom, St1, En1 - St1)
End Function
CutFrom, Optional Start1, Optional End1
Views 5,332
Downloads 1,477
CodeID
DB ID
ANmarAmdeen
615
Revisions
v3.0
Wednesday
April
3
2024