C# 字符“//”路径分隔符

发布于 2024-10-10 07:44:00 字数 239 浏览 0 评论 0原文

是否可以在我做的另一个地方使用 char“//”?我在Path中寻找,但找不到。

  string separator = "//";

我是说 '/'。

我使用:

static string sep = System.IO.Path.PathSeparator.ToString();

但它返回:';'。为什么?

Is there possible to use char "//" another there I did it? I looked for in Path, but I can't find it.

  string separator = "//";

I mean '/'.

I used:

static string sep = System.IO.Path.PathSeparator.ToString();

but it returns: ';'. Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一页 2024-10-17 07:44:00

Path.DirectorySeparatorChar 为您提供用于分隔路径中的目录的字符,即您路径中使用它。

Path.PathSeparator 为您提供用于在环境变量中分隔路径的字符,即您在路径之间使用它。

例如,系统的 PATH 环境变量通常会列出操作系统将在其中查找要运行的应用程序的多个路径。

在 Windows 上,Path.PathSeparator;Path.DirectorySeparatorChar\。两个路径将存储在环境变量中,如下所示:

set PATH="C:\first\path;C:\second\path"

Path.DirectorySeparatorChar gives you the character used to separate directories in a path, i.e. you use it in paths.

Path.PathSeparator gives you the character used to separate paths in environment variables, i.e. you use it between paths.

For example, your system's PATH environment variable will typically list multiple paths where the OS will look for applications to run.

On Windows, Path.PathSeparator is ;, and Path.DirectorySeparatorChar is \. Two paths would be stored in an environment variable like this:

set PATH="C:\first\path;C:\second\path"
冷月断魂刀 2024-10-17 07:44:00

System.IO.Path.PathSeparator< /code>你真正在寻找什么?还有 .DirectorySeparatorChar< /a> 和其他。请参阅“”下的 System.IO.Path 类领域”。

详细地说,路径分隔符用于将多个完整路径连接在一起(想想 PATH 环境变量)。听起来您正在寻找目录分隔符,该分隔符用于在单个路径中分隔文件夹/文件。 (在 Windows 中,通常是 \,而 / 基本上在其他地方)。

Is System.IO.Path.PathSeparator what you're actually looking for? There's also .DirectorySeparatorChar and others. See the System.IO.Path class under "Fields".

To elaborate, a path separator is used to concatenate multiple full paths together (think the PATH environmental variable). It sounds like you're after the directory separator, which is used within a single path to split out folders/ files. (In windows it's commonly \, and / basically elsewhere).

梦回梦里 2024-10-17 07:44:00

它是只读的,您无法更改它。路径表示运行框架的操作系统和您的应用程序可以理解的路径。如果您使用任何其他值,操作系统将无法理解它。世界上没有操作系统能够理解“a//b//c”路径。但是您可以拥有包含此类路径的任意字符串,除非它们不是操作系统可理解的文件路径,并且您可以将它们称为其他名称。

It's read only, you can't change it. A Path represents a path that the operating system running the framework and your application understands. If you use any other value, the OS won't understand it. There's no OS in the world which understands "a//b//c" paths. But you can have arbitrary strings which contain paths like that, except they won't be OS-understandable file paths, and you can call them something else.

夏至、离别 2024-10-17 07:44:00

对于正斜杠“/”,请使用 Path.AltDirectorySeparatorChar 。
您可以在此处查看完整列表
https://learn. microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=net-7.0

For Forward slash '/' use Path.AltDirectorySeparatorChar .
you can check full list here
https://learn.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=net-7.0

策马西风 2024-10-17 07:44:00

它等于 Path.PathSeparator ,最好用这个,

It's equal to Path.PathSeparator, it's better to use this,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文