我有以下似乎有效的功能。这是在设计代码中:
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
它返回参数word在字段fText中的位置。
这是一种有效的方法吗?
容易坏吗?
有更好的解决方案吗?