Cuts a string from certain char till certain char, can be used to cut left, right and mid section of a string.
Edit 2023-04-23: Adding 'ByVal' to 'StartFromChar' to avoid changing it in VBA
Remove 'ByVal' when using for ASP
Function CutString(FromString, CutFrom, ToString, ByVal StartFromChar)
' Cuts a string from a string starting from a specific charactor and until a specific charactor
' FromString is the char to cut from (not included)
' Case-sensetive
' ToString is the char to stop cut to (after FromString is found) (not included)
' CurFrom is the string to cut from
' StartFromChar is the number of charactor to start search from
' If CutFrom is not given or not found, it will be assumed as 1
' If ToString is not given or not found, it will be assumed as the length of the string
CutString = ""
StartFromChar = 1
If CutFrom > "" Then
If InStr(StartFromChar, FromString, CutFrom) > 0 Then
StartFromChar = InStr(StartFromChar, FromString, CutFrom) + Len(CutFrom)
End If
End If
CutString = Mid(FromString, StartFromChar)
If ToString > "" Then
End1 = Len(FromString)
If InStr(StartFromChar, FromString, ToString) > 0 Then
End1 = InStr(StartFromChar, FromString, ToString) - StartFromChar
Else
End If
CutString = Mid(FromString, StartFromChar, End1)
End If
End Function
' Cuts a string from a string starting from a specific charactor and until a specific charactor
' FromString is the char to cut from (not included)
' Case-sensetive
' ToString is the char to stop cut to (after FromString is found) (not included)
' CurFrom is the string to cut from
' StartFromChar is the number of charactor to start search from
' If CutFrom is not given or not found, it will be assumed as 1
' If ToString is not given or not found, it will be assumed as the length of the string
CutString = ""
StartFromChar = 1
If CutFrom > "" Then
If InStr(StartFromChar, FromString, CutFrom) > 0 Then
StartFromChar = InStr(StartFromChar, FromString, CutFrom) + Len(CutFrom)
End If
End If
CutString = Mid(FromString, StartFromChar)
If ToString > "" Then
End1 = Len(FromString)
If InStr(StartFromChar, FromString, ToString) > 0 Then
End1 = InStr(StartFromChar, FromString, ToString) - StartFromChar
Else
End If
CutString = Mid(FromString, StartFromChar, End1)
End If
End Function
FromString, CutFrom, ToString, ByVal StartFromChar
CutString("Hello-World-Cruel", "", "-", 1) = "Hello"
CutString("Hello-World-Cruel", "-","-", 1) = "World"
CutString("Hello-World-Cruel", "-","-", 1) = "World"
Views 6,541
Downloads 1,581
CodeID
DB ID
ANmarAmdeen
614
Revisions
v4.0
Sunday
April
23
2023