C#路径拼接方法

1、EnsureEndsWith(char c)

Adds a char to end of given string if it does not ends with the char.

使用示例:

string url = baseUrl.EnsureEndsWith('/') + route;

说明:如果字符串最后不是该字符,则增加这个字符到字符串的最后。适用于路径,因为不明确路径的最后是否是/,使代码更加优雅。

 

2、Combine(string path1, string path2)

Combines two strings into a path.

使用示例:var filePath = Path.Combine(uploads, file.FileName);

 

posted @ 2021-11-05 11:25  奈何碧落黄泉  阅读(2195)  评论(0编辑  收藏  举报