Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

Find last occurance of a substring within a string

I have the following string: which begins after the last '//':

"abc//def//hij//I am the owner"

I need to return "I am the owner" which always begins after the last '//':

The length of the final substring can vary.

What is the best way to do this?

Thanks
SOLUTION
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use this Regex and then remove the 2 slashes at the beginning:

//(?:.(?!//))+$

Open in new window

Dim myString As String = "abc//def//hij//I am the owner"
Dim arr As String()
arr = myString.Split(CChar("//")
messagebox.show(arr(arr.Length).ToString

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, this should work:
        Dim myString As String = "abc//def//hij//I am the owner"
        Dim arr As String()
        myString.Replace("//", "#")
        arr = myString.Split(CChar("#"))
        MessageBox.Show(arr(arr.Length)).ToString()

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See last comment
Avatar of Dovberman

ASKER

Thanks for all the responses. These gave me hints for working out a solution.