版本: 2022.3
语言英文
  • C#

Path.Combine(string, string)

建议修改

成功!

感谢您帮助我们提高Unity文档的质量。尽管我们无法接受所有提交,但我们确实阅读了用户提出的每一条建议,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您提出的修改无法提交。请稍后再试,并感谢您花时间帮助我们提高Unity文档的质量。

关闭

取消

描述

连接两个路径字符串。

如果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" } }