In my application, i am trying to get the name of a file, from a string retrieved from a 'content-header' tag from a server. The filename looks like \"uploads/2014/03/filename.zip\"
(quotations included in value).
I have tried using Path.GetFileName(string);
to get just the file name but it throws an exception stating that there are illegal characters in the path.
What should i use to get just filename.zip
returned? is a regex the best way to trim this string off or is there a better one?
the \"uploads/2014/03/
part will always be the same length. The filename.zip
can be any filename and extension, im just using that as an example. But the numbers may vary. It sounds like a job for a regex to me, but i have no idea how to use regular expressions.
You can try something like this:
This should work if the format is always like
\"uploads/someNumber/someOtherNumber/filename\"
.In order to make it more safe you might want to useEnumerable.Last
method afterSplit
: