How do I get this?

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hello,

I have a string like this:
~/Uploads/18/MyImage.png

Now I only need the directory like this:
~/Uploads/18/

What's the best way to do this?
Or how can I do this in C#?

Thanks!
 
try:

string strPath="~/Uploads/18/MyImage.png";

//get your directory in a string
string strDirectory=strPath.Substring(0,13);
//where 0 is the start index and 13 is the length of
//the string you want

hope that helps,
 
string s = "~/Uploads/18/MyImage.png";
string s = s.SubString( 0, s.LastIndexOf( "/" ) - 1 ); (since it is a path,
you are guaranteed to not have any / in the filename...I think)

bill
 
Back
Top