如何拼接下面的字符串 [英] How to splite the below string
本文介绍了如何拼接下面的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下字符串
string path = @C:\Program Files \TEST \Project Name\Tester.exe;
我需要字符串路径值最多为C:\Program Files \TEST \ Project Name \仅
这是我的代码
string strt = path.Remove(path.Length-10);
但是我不想使用长度怎么做
请帮帮我。
谢谢,
RG
string path = @ C:\Program Files \TEST \Project Name\Tester.exe 跨度>;
FileInfo fi1 = new FileInfo(path);
if (!fi1 .Exists)
{
return < /跨度>;
}
// 此行将返回文件路径
string dirPath = fi1.DirectoryName;
Hi,
I have a string like below
string path = @"C:\Program Files\TEST\Project Name\Tester.exe";
I need string path value up to "C:\Program Files\TEST\Project Name\" only
this is my code
string strt = path.Remove(path.Length-10);
but I don't want to use length how to do it
please help me.
Thanks,
RG
解决方案
Try this
string path = @"C:\Program Files\TEST\Project Name\Tester.exe"; FileInfo fi1 = new FileInfo(path); if (!fi1 .Exists) { return; } //This line will return the file path string dirPath = fi1.DirectoryName;
这篇关于如何拼接下面的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文