TrimEnd
Brian Element
Forums
This function is the opposite of the TrimStart custom function. It will remove an ending character from a field. The first parameter is the string or character field to remove the charcters from, the second parameter is the character to remove. You would call the custom function in the equation editor using #TrimEnd(Character Field, Character to remove).
Option Explicit
Function TrimEnd(p1 As String,p2 As String) As String
Dim i As Integer
Dim tempString As String
tempString = p1
For i = Len(p1) To 1 Step -1
If Mid(p1,i,1) = p2 Then
tempString = Mid(p1, 1, i - 1)
Else
trimend = tempString
Exit For
End If
Next i
End Function
nice....
i have not made a function for this, but it is exactly the way i use it most time...
have a look:
Sub Main
Dim sText As String
Dim sCutLeft As String
Dim sCutRight As String
sText = "Hello World!"
'display sText without the first character
sCutLeft = iMid(sText, 2, iLen(sText))
'display sText without the last character
sCutRight = iMid(sText, 1, iLen(sText)-1)
MsgBox sText, 0, "Original Text"
MsgBox sCutLeft, 0, "Cut from Left"
MsgBox sCutRight, 0, "Cut from Right"
End Sub
cheers,
chris