URL的路径功能 [英] Path functions for URL
问题描述
我想将Path类的功能(GetDirectoryName
,GetFileName
,Combine
等)用于URL格式带有斜杠(/)的路径.
I want to use functions of Path class (GetDirectoryName
, GetFileName
, Combine
,etc.) with paths in URL format with slash (/).
我的路径示例:
"xxx://server/folder1/folder2/file"
我试图用Path
函数来完成这项工作,最后只更换了分隔符.
I tried to do the job with Path
functions and in the end just replaced the separator.
我发现GetDirectoryName
函数不能正确替换斜杠:
I've found that the GetDirectoryName
function does not correctly replace the slashes:
Path.GetDirectoryName(@"xxx://server/folder/file") -> @"xxx:\server\folder"
就像您看到一个斜线丢失一样.
Like you see one slash is lost.
如何使Path函数使用替代"分隔符?
How can I cause the Path functions to use the 'alternative' separator?
我可以使用其他具有相同功能的类吗?
Can I use another class with the same functionality?
推荐答案
恐怕GetDirectoryName
,GetFileName
,Combine
等.在定义中使用 Path.DirectorySeparatorChar 想要 Path.AltDirectorySeparatorChar .
I'm afraid GetDirectoryName
, GetFileName
, Combine
,etc. use Path.DirectorySeparatorChar in the definition and you want Path.AltDirectorySeparatorChar.
由于Path是一个密封的类,所以我认为唯一的方法是字符串替换.您可以将Path.DirectorySeparatorChar
('\')替换为Path.AltDirectorySeparatorChar
('/')和Path.VolumeSeparatorChar
(': ')和:/"
And since Path is a sealed class, I think the only way to go about is string replacement.You can replace Path.DirectorySeparatorChar
('\') with Path.AltDirectorySeparatorChar
('/') and Path.VolumeSeparatorChar
(':') with ":/"
这篇关于URL的路径功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!