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