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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM