C# 字符“//”路径分隔符
是否可以在我做的另一个地方使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Path.DirectorySeparatorChar
为您提供用于分隔路径中的目录的字符,即您在路径中使用它。Path.PathSeparator
为您提供用于在环境变量中分隔路径的字符,即您在路径之间使用它。例如,系统的
PATH
环境变量通常会列出操作系统将在其中查找要运行的应用程序的多个路径。在 Windows 上,
Path.PathSeparator
为;
,Path.DirectorySeparatorChar
为\
。两个路径将存储在环境变量中,如下所示: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;
, andPath.DirectorySeparatorChar
is\
. Two paths would be stored in an environment variable like this:是
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).它是只读的,您无法更改它。路径表示运行框架的操作系统和您的应用程序可以理解的路径。如果您使用任何其他值,操作系统将无法理解它。世界上没有操作系统能够理解“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.
对于正斜杠“/”,请使用 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
它等于
Path.PathSeparator
,最好用这个,It's equal to
Path.PathSeparator
, it's better to use this,