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

后端 未结 3 1493
鱼传尺愫
鱼传尺愫 2021-01-02 14:13

How to convert

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

into

String path = @\"C:\\A

3条回答
  •  感动是毒
    2021-01-02 14:50

    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\
    

提交回复
热议问题