C# alternative to VBScript InStrRev function

I need to search a string for multiple occurences of numbers separated by a hyphen (-).  A typical example would be the string "seahorse_se-120-181-3794-pr", where I need the last two sets of digits - the 181 and the 3794.  These numbes are not a fixed number of digits - they can be from 1 to 4 digits in length; and because nothing is ever easy, the string in front of the numbers (the "seahorse_se-120-" in the example above) can be any length also.  I am using VBScript in an ASP page right now, and the InStrRev function works fine to help me extract what I need.  Is there a C# equivalent?

Thanks for your help,

Who is Participating?
AvonWyssConnect With a Mentor Commented:
What you are looking for is string.LastIndexOf() - it's a .NET framework thing, not a C# specific thing.
My C# isnt the best, but i have a VBA version of it, tried to convert it the VB .Net (dont have it at hand so cant test)


Public Function InStrRev(StringCheck As String, StringMatch As String, Optional Start As Long = -1)

    Dim sTemp As String

    If Start <= 0 Then
        sTemp = StringCheck
        sTemp = Left(StringCheck, Start)
    End If
    Do Until sTemp = ""
        If Mid(StringCheck, Len(sTemp), Len(StringMatch)) = StringMatch Then
            Exit Do
        End If
        sTemp = Left(sTemp, Len(sTemp) - 1)
    If sTemp = "" Then
        return 0
        return Len(sTemp)
    End If

End Function
(But for your task, I'd use a regular expression anyways.)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.