動作するように見える次の機能があります。これは設計コードにあります:
Method findFirst(word As String) As Integer
foundPosition As integer
Set foundPosition To -1
wordLen As integer
Set wordLen To len(word)
startingPoint As integer
Set startingPoint To (len(Text)- 1) - wordLen
For iPosition As integer From startingPoint To 0 Step -1
If substring(iPosition, wordLen) = word Then
foundPosition = iPosition
End If
Next iPosition
Return foundPosition
End Method
で実装されたVB.NET
私は次のものを持っています:
Public Function findFirst(word As String) As Integer
Dim foundPosition As Integer = -1
Dim wordLen As Integer = word.Length
Dim startingPoint As Integer = (fText.Length - 1) - wordLen
For iPosition As Integer = startingPoint To 0 Step -1
If fText.Substring(iPosition, wordLen) = word Then
foundPosition = iPosition
End If
Next iPosition
Return foundPosition
End Function
フィールドfText内のパラメータwordの位置を返します。
これは有効なアプローチですか?
壊れやすいですか?
より良い解決策はありますか?