Extracting Text from String Variable

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
LVL 1
rito1Asked:
Who is Participating?
 
Paul JacksonConnect With a Mentor Software EngineerCommented:
string mystring = 'http://localhost:80/myfoldername';
string mynewstring = mystring.SubString(mystring.LastIndexOf('/')+1);
0
 
sshah254Connect With a Mentor Commented:
You should be able to use LastIndexOf and Substring.

Ss
0
 
rito1Author Commented:
Thanks both.

Rit
0
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.