我正在尝试拆分字符串。这是字符串。
string fileName = "description/ask_question_file_10.htm"
我必须从这个字符串中删除“description/”和“.htm”。所以我正在寻找“ask_question_file_10”的结果。我必须寻找“/”和“.htm”。感谢任何帮助。
最佳答案
您可以使用 Path.GetFileNameWithoutExtension Method :
string fileName = "description/ask_question_file_10.htm";
string result = Path.GetFileNameWithoutExtension(fileName);
// result == "ask_question_file_10"
关于c# - 如何拆分字符串以获得文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7691546/