如何拆分字符串以获取文件名?

nav*_*100 4 c#

我想分裂字符串.这是字符串.

string fileName =   "description/ask_question_file_10.htm"
Run Code Online (Sandbox Code Playgroud)

我必须从此字符串中删除"description /"和".htm".所以结果我正在寻找"ask_question_file_10".我必须寻找"/"和".htm"我感谢任何帮助.

dtb*_*dtb 19

您可以使用Path.GetFileNameWithoutExtension方法:

string fileName = "description/ask_question_file_10.htm";

string result = Path.GetFileNameWithoutExtension(fileName);
// result == "ask_question_file_10"
Run Code Online (Sandbox Code Playgroud)


Paw*_*ski 5

string fileName = Path.GetFileNameWithoutExtension("description/ask_question_file_10.htm")
Run Code Online (Sandbox Code Playgroud)