There are many ways to do a simple string inversion, character by character, with VB/A. This function uses the Mid$ keyword as a function and as a statement to do it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
'Reverses a string, eg "1234567890" becomes "0987654321" 'Particularity: uses Mid$() as a getter and as a setter. Public Function ReverseString(ByVal psString As String) As String Dim sReverse As String Dim iLen As Integer Dim i As Integer iLen = Len(psString) If iLen = 0 Then Exit Function sReverse = Space$(iLen) For i = 1 To iLen Mid$(sReverse, iLen - i + 1, 1) = Mid$(psString, i, 1) Next i ReverseString = sReverse End Function |
Recent Comments