Get part of a string

Posted on 2011-10-31
Last Modified: 2012-08-14
Hello, I have a string that looks like this:
"~/SurveyImages/Survey - 100727/Tween Deck - UPS Room D2305/Deck, Overhead, Walls, Bulkhead/PICT0147.jpg"

Im populating a datalist with images from this directory: ~/SurveyImages/Survey - 100727/
In the directory there are numerous folders and pitcures within. I need to aquire everything after "~/SurveyImages/Survey - 100727/
and before /PICT0147.jpg"

I will populate a label in the datalist with the resulting string to show the user which folder or where is the directory structure the image can be found.

How can I accomplish this?

Question by:gogetsome
    LVL 74

    Accepted Solution

    What about this?

    string parent = System.IO.Path.GetDirectory("~/SurveyImages/Survey - 100727/Tween Deck - UPS Room D2305/Deck, Overhead, Walls, Bulkhead/PICT0147.jpg");
    string cropped = parent.Replace(""~/SurveyImages/Survey - 100727/", string.Empty);

    Open in new window

    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Remove the extra quote in the beginning of line 2  = )

    Author Comment

    Cool, that does get rid of the first portion. How do I get rid of the image portion at the end of the string. My guess is to remove everything after the last "/"
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Sorry, it's GetDirectoryName, not GetDirectory.

    Author Closing Comment

    Thanks for your help! Got the last portion with this:
    Dim q As String = "/" & s.Substring(s.LastIndexOf("/") + 1)

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now