Листинг 2. Варианты реализация функции StrReverse традиционными средствами Basic
Function ReverseString(sSource As String) As String
Dim sReverse As String
Dim i%
For i = Len(sSource) To 1 Step -1
sReverse = sReverse & Mid$(sSource, i, 1)
Next i
ReverseString = sReverce
End Function
Public Function ReverseStringMy(Source$) As String
Dim Reverse$, i%, j%
Reverse$ = Space$(Len(Source$))
For i = Len(Source$) To 1 Step -1
j = j + 1
Mid$(Reverse$, j, 1) = Mid$(Source, i, 1)
Next
ReverseStringMy = Reverse$
End Function
Public Function ReverseStringByteMy(Source$) As String
' revised procedure (VBPJ 12'98, p.129)
Dim bString() As Byte, bString2() As Byte
Dim i%, j%, iLen%
'
bString = Source$
iLen = Len(Source$) * 2 - 1
ReDim bString2(iLen)
For i = iLen To 0 Step -2
bString2(j) = bString(i - 1):
bString2(j + 1) = bString(i)
j = j + 2
Next i
ReverseStringByteMy = bString2
End Function