Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I split a string to obtain a filename?

Tags:

c#

I am trying to split the string. Here is the string.

string fileName =   "description/ask_question_file_10.htm"

I have to remove "description/" and ".htm" from this string. So the result I am looking for "ask_question_file_10". I have to look for "/" and ".htm" I appreciate any help.

like image 626
nav100 Avatar asked Oct 07 '11 18:10

nav100


2 Answers

You can use the Path.GetFileNameWithoutExtension Method:

string fileName = "description/ask_question_file_10.htm";

string result = Path.GetFileNameWithoutExtension(fileName);
// result == "ask_question_file_10"
like image 61
dtb Avatar answered Sep 28 '22 08:09

dtb


string fileName = Path.GetFileNameWithoutExtension("description/ask_question_file_10.htm")
like image 41
Pawel Lesnikowski Avatar answered Sep 28 '22 09:09

Pawel Lesnikowski