User login

Remove Characters From End of String

This VBA function will remove characters from the end of a string:


Function removeCharactersFromEnd(str As String, char As String)
Do While Right(str, 1) = char
str = Left(str, Len(str) - 1)
Loop
removeCharactersFromEnd = str
End Function

So, for example, if you have a string similar to the following:
str = "abc____"
you call this function as follows:
str = removeCharactersFromEnd(str, "_")
The resulting string will be : "abc"

Access Individual Characters In String

Here is how you access individual characters in a string:

Dim str As String
Dim i As Integer
str = "abc"
For i = 1 To Len(str)
Debug.Print Mid(str, i, 1)
Next

Java

If you are looking for a way to remove the last character in Java go to this page.