如何拆分附件名称和扩展名? [英] How to split the attachment name and extension?
问题描述
我的附件名称是:TimeSheet URD V1.0.doc
i want将其拆分为 TimeSheet URD V1.0 和 doc 。
我使用str [ ] strWords = str.Split('。')。这段代码只给了我TimeSheet URD V1。
如何在没有扩展名的情况下获得完整的文件名?
请帮我解决这个问题。
谢谢。
Hi,
My attachment name is : TimeSheet URD V1.0.doc
i want to split it as "TimeSheet URD V1.0" and "doc".
I used str[] strWords=str.Split('.'). This code gave me only "TimeSheet URD V1".
How can i achieve to get the full file name without extension?
Please help me to resolve this issue.
Thanks.
推荐答案
1 。
1.
String returnValue = Path.GetFileNameWithoutExtension(path);
2.
2.
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
String returnValue = openFileDialog1.SafeFileName;
}
3.
使用lastindexof( 。),而不是indexof(。)
3.
use lastindexof(".") ,not indexof (".")
strFilePaht.Substring(path.LastIndexOf("\\") + 1, path.Length - 1 - path.LastIndexOf("\\"));
strFilePaht.Substring(path.LastIndexOf("."), path.Length - path.LastIndexOf("."));
请使用:
Hi, Use this:
string s = "TimeSheet URD V1.0.doc";
int i = s.LastIndexOf('.');
string lhs = i < 0 ? s : s.Substring(0, i),
rhs = i < 0 ? "" : s.Substring(i + 1);
来源:
最佳方式对BREAK- a-string-on-the-point-on-c-sharp
它有效!
Got this source from:
Best-way-to-break-a-string-on-the-last-dot-on-c-sharp
and it works!
这篇关于如何拆分附件名称和扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!