删除多余的反斜杠“ \”从C#中的字符串文件路径 [英] Remove Extra back slash "\" from string file path in c#

查看:628
本文介绍了删除多余的反斜杠“ \”从C#中的字符串文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转换

字符串路径= @ C:\Abc\Omg\Why\Me\\ \\\\\\\\;

进入

字符串路径= @ C:\Abc\Omg\为什么\我\

我的方法是首先反向 字符串,然后删除所有 \ ,直到我们先获得 char ,然后再次<< c $ c>反向。

My approach is to first reverse the string and then remove all the "\" till we get first char, and the reverse it again.

如何在C#中执行此操作,是否有任何用于此操作的方法?

How to do this in C#, is there any method for such operation?

推荐答案

您可以使用 Path 静态类:

string path = Path.GetFullPath(@"C:\Abc\Omg\Why\Me\\\\\\\\\\\\\\\\\\\\\");

此操作后,变量 path 将包含最低版本:

After this operation, variable path will contain the minimal version:

C:\Abc\Omg\Why\Me\

这篇关于删除多余的反斜杠“ \”从C#中的字符串文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆