当前位置 : 主页 > 编程语言 > c语言 >

vb.net – VB .net – 在字符串中查找第N个char的最短和最快的方法?

来源:互联网 收集:自由互联 发布时间:2021-06-24
实现这一目标的专业方法是什么? 谢谢. 我已经无耻地从 this question中删除了示例并将其从C#转换为VB.net. Public Function GetNthIndex(s As String, t As Char, n As Integer) As Integer Dim count As Integer = 0
实现这一目标的专业方法是什么?

谢谢.

我已经无耻地从 this question中删除了示例并将其从C#转换为VB.net.

Public Function GetNthIndex(s As String, t As Char, n As Integer) As Integer
    Dim count As Integer = 0
    For i As Integer = 0 To s.Length - 1
        If s(i) = t Then
            count += 1
            If count = n Then
                Return i
            End If
        End If
    Next
    Return -1
End Function
网友评论