Листинг 3. Варианты реализация функции InstrRev традиционными средствами Basic
Public Function RevInstrMy(Source$, SubString$) As Integer
Dim i%, iStart%, iSub%
iSub = Len(SubString$)
iStart = Len(Source$) - iSub + 1
For i = iStart To 1 Step -1
If Mid$(Source$, i, iSub) = SubString$ Then
RevInstrMy = i: Exit Function
End If
Next
End Function
Public Function InstrReverseMy(Source$, SubString$) As Integer
Dim i%
Do
i = InStr(i + 1, Source$, SubString$)
If i <= 0 Then Exit Do
InstrReverseMy = i
Loop
End Function
Public Function RevInstrByteMy(Source$, SubString$) As Integer
Dim i%, bytArray() As Byte, iBytes%
bytArray = Source$
iBytes = Len(Source$) * 2 - 2
For i = iBytes To 0 Step -2
If Chr(bytArray(i)) = SubString Then
RevInstrByteMy = i / 2 + 1
Exit Function
End If
Next
End Function
Public Function RevInstrByteMy2(Source$, SubString$) As Integer
Dim i%, bytArray() As Byte, bytSub As Byte, iBytes%
bytArray = Source$: bytSub = Asc(SubString)
iBytes = Len(Source$) * 2 - 2
For i = iBytes To 0 Step -2
If bytArray(i) = bytSub Then
RevInstrByteMy2 = i / 2 + 1
Exit Function
End If
Next
End Function