Remove Extra back slash “\” from string file path in c#

后端 未结 3 1848
滥情空心
滥情空心 2021-01-02 14:31

How to convert

\"String path = @\"C:\\Abc\\Omg\\Why\\Me\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\";

into

String path = @\"C:\\A

3条回答
  •  一整个雨季
    2021-01-02 14:45

    You can just construct path using the Path static class:

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

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

    C:\Abc\Omg\Why\Me\
    

提交回复
热议问题