Solved

Extracting Text from String Variable

Posted on 2011-03-23
3
338 Views
Last Modified: 2012-05-11
Hi All,

I have the follwing URL stored within a string variable...

http://localhost:80/myfoldername

Using C#, how can I extract everything after the last '/' and store in a separate variable. In this example its 'myfoldername'? 'myfoldername' will vary in characters/size so the next time it could be called 'abcfolder' for example.

Thanks,

Rit
0
Comment
Question by:rito1
3 Comments
 
LVL 9

Assisted Solution

by:sshah254
sshah254 earned 200 total points
ID: 35202991
You should be able to use LastIndexOf and Substring.

Ss
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 300 total points
ID: 35203149
string mystring = 'http://localhost:80/myfoldername';
string mynewstring = mystring.SubString(mystring.LastIndexOf('/')+1);
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 35203169
Thanks both.

Rit
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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