How to return a Padded String with Blanks on Right

1
2
3
4
5
6
'String Manipulation - How to return return a Padded String with Blanks on Right
Option Explicit
 
Public Function PadR(ByVal strExpression As String, ByVal iWidth As Integer) As String
   PadR = Left$(RTrim(strExpression) & Space(iWidth), iWidth)
End Function

How to return everything between ‘string2′ in ‘string1′

1
2
3
4
5
6
7
8
9
10
11
12
'String Manipulation - How to return everything between 'string2' in 'string1'
Option Explicit
 
Public Function GetStringBetween(ByVal sExpression As String, ByVal sStartString As String, _
    ByVal sEndString As String) As String
    Dim iStartPos As Integer, iEndPos As Integer
    iStartPos = InStr(sExpression, sStartString)
    iEndPos = InStr(sExpression, sEndString)
    If iStartPos <> iEndPos And iStartPos <> 0 And iEndPos <> 0 Then
        GetStringBetween = Mid$(sExpression, iStartPos + Len(sStartString), iEndPos - 1)
    End If
End Function

How to return everything before ‘string2′ in ‘string1′

1
2
3
4
5
6
7
8
9
10
'String Manipulation - How to return everything before 'string2' in 'string1'
Option Explicit
 
Public Function SubstringBefore(ByVal sString1 As String, ByVal sString2 As String)
    Dim iPos As Integer
    iPos = InStr(sString1, sString2)
    If iPos <> 0 Then
        SubstringBefore = Mid$(sString1, 1, iPos - 1)
    End If
End Function

How to return everything after ‘string2′ in ‘string1′

1
2
3
4
5
6
7
8
9
10
'String Manipulation - How to return everything after 'string2' in 'string1'
Option Explicit
 
Public Function SubstringAfter(ByVal sString1 As String, ByVal sString2 As String)
    Dim iPos As Integer
    iPos = InStr(sString1, sString2)
    If iPos <> 0 Then
        SubstringAfter = Mid$(sString1, iPos + Len(sString2))
    End If
End Function

How to check if a given string ends with a given substring

1
2
3
4
5
6
'String Manipulation - How to check if a given string ends with a given substring
Option Explicit
 
Public Function IsEndsWith(ByVal sSource As String, ByVal sText As String) As Boolean
    IsEndsWith = (Right$(sSource, Len(sText)) = sText)
End Function