我在本地服务器上有文件,地址为groupBy
。我需要动态删除服务器地址,并将其替换为在表单中其他位置选择的其他服务器地址。服务器名称可以是不同的长度,因此,我无法使用\\localServerAddress\Folder\Program.exe
函数。
所以给出了输入
string.Substring
我想要结果
\\localServerAddress\Folder\Program.exe
答案 0 :(得分:2)
如果您一直在与UNC合作
然后
string toRemove = new Uri(yourString).host;
string newString = yourString.Replace(String.format(@"\\{0})",toRemove)
, String.format(@"\\{0})",whateveryouwant));
答案 1 :(得分:1)
使用此方法:
eval
答案 2 :(得分:0)
您可以使用以下内容:
void Main()
{
string path = @"\\localServerAddress\Folder\Program.exe";
UriBuilder bld = new UriBuilder(path);
bld.Host = "NewServer";
Console.WriteLine(bld.Uri.LocalPath);
}
结果:\\newserver\Folder\Program.exe
答案 3 :(得分:-1)
string text = @"\\test\FolderName\foo.exe";
text = text.Replace('\\', '-'); \\ this is done as I was not able to make the regex **\\\\\\(.)*?\\** , work.
Regex rg = new Regex("--.*?-"); \\ if in case the above mentioned regex is made to work correctly please replace the regex with the same.
text = rg.Replace(text, "");
Console.WriteLine(text.Replace('-', '\\'));
Console.Read();