Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find last occurance of a substring within a string

Posted on 2013-01-03
10
Medium Priority
?
435 Views
Last Modified: 2013-01-08
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
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 30

Assisted Solution

by:Randy Downs
Randy Downs earned 300 total points
ID: 38740784
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38740796
You can use this Regex and then remove the 2 slashes at the beginning:

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

Open in new window

0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 38740815
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Assisted Solution

by:David L. Hansen
David L. Hansen earned 450 total points
ID: 38740832
In C#:
string myString = null;
myString = "abc//def//hij//I am the owner";
string[] arr = null;
arr = myString.Split(Convert.ToChar("//"));
messagebox.show(arr(arr.Length)).ToString();

Open in new window

0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 38740872
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

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 450 total points
ID: 38740889
Dim input As String = "abc//def//hij//I am the owner"
            Dim result As String

            result = input.Substring(input.LastIndexOf("//") + 2)
0
 

Accepted Solution

by:
Dovberman earned 0 total points
ID: 38741317
There were several answers, but this is what worked for me.

             intFileCount += 1;
                strFileName = FileName;  // Full path of filename

                // strFileName1 is the actual file name is after last occurance of '\\'

                intLastPos = strFileName.LastIndexOf("\\");
                intStartPos = intLastPos+2;
                intFileNameLength = strFileName.Length;

                strFileName1 = strFileName.Substring(intStartPos, (intFileNameLength - intStartPos));
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38742257
No close, @Number-1 posted link to the answer.

Accept this one.
http://www.experts-exchange.com/Programming/Languages/.NET/Q_27983783.html#a38740784
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38742258
See last comment
0
 

Author Closing Comment

by:Dovberman
ID: 38754098
Thanks for all the responses. These gave me hints for working out a solution.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question