您的位置:首页 > 编程语言 > C#

C# 路径拼接(将多个字符串组合成一个路径)

2017-02-22 17:33 2807 查看
        C#将多个字符串组合成一个路径,可利用System.IO.Path类中的Combine(String,String)方法。

        命名空间为:using System.IO;

示例:

string path1 = @"D:\temp";
string path2 = "result.txt";
string newPath = Path.Combine(path1, path2); // newPath = "D:\temp\result.txt";




Combine(String, String)将两个字符串组合成一个路径。




Combine(String, String, String)将三个字符串组合成一个路径。




Combine(String, String, String, String)将四个字符串组合成一个路径。




Combine(String[])将字符串数组组合成一个路径。

        参考资料:MSDN:Path 类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息