Version: 2022.3

Path.Combine(string, string)

切换到手册

描述

连接两个路径字符串。

如果 path1 不是以有效的分隔符结束,则 DirectorySeparatorChar 会在连接前附加到 path1。

using System.IO;
using UnityEditor;
using UnityEngine;

public class CombinePathsExample : MonoBehaviour { [MenuItem("Example/CombinePaths")] static void CombinePaths() { string path1 = "Assets"; string path2 = "example.txt";

Debug.Log(Path.Combine(path1, path2)); // The result is "Assets/example.txt" } }