Skip to content

Remove variable ends of a string.

Andre

Asked May 18, 2007, 12:19 AM EDT1 answer
Share
LinkedInX
Hi there,

I have for example a string like this:

/bedrijfsgroep/dienstencentrum/pd/catalogus/niveau0/niveau1/niveau2/test.doc

I want to remove for example till this so that I got this string:

/bedrijfsgroep/dienstencentrum/pd/catalogus/niveau0/

Sometimes it will be this:

/bedrijfsgroep/dienstencentrum/pd/catalogus/niveau0/niveau1/

And so on. How can I remove from the till for example niveau0?

Please can someone help me out with this one?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    use string directory = System.IO.Path.GetDirectoryName("/bedrijfsgroep/dienstencentrum/pd/catalogus/niveau0/niveau1/niveau2/test.doc"); if you want to strip off an additional directory, use a string function newPath = newPath.Substring(0, newPath.LastIndexOf('\\')); Note that after you use GetDirectoryName, all your forward slashes will be converted to backslashes as is standard for Window Paths. (Seems my return characters in this post are being hosed)
    0