【问题标题】:VisualStudio - How to escape this charsVisual Studio - 如何转义这个字符
【发布时间】:2012-11-05 10:31:53
【问题描述】:

我想我需要在这里转义特殊字符:

Process.Start(userSelectedFilePath, "\u0007" & ThisDir.Path & "\u000B" & checkedpath1 & "\u0007")

结果需要像:userelecfilepath "a blackquoted path\and other folder"

我做错了什么?

谢谢

更新

解决方案:

ControlChars.Quote & Path.Combine(ThisDir.Path, checkedpath1) & ControlChars.Quote

【问题讨论】:

    标签: visual-studio escaping character special-characters unicode-escapes


    【解决方案1】:
    Process.Start(userSelectedFilePath, Path.Combine(ThisDir.Path, checkedpath));
    

    Path.Combine

    如果 path1 不是驱动器引用(即“C:”或“D:”)并且不 以定义的有效分隔符结尾 DirectorySeparatorChar、AltDirectorySeparatorChar 或 VolumeSeparatorChar,DirectorySeparatorChar 附加到 path1 在连接之前。

    如果 path2 不包含根目录(例如,如果 path2 没有启动 带分隔符或驱动器规范),结果是 两个路径的连接,中间有分隔符 特点。如果 path2 包含根,则返回 path2。

    如果参数有空格,则不对其进行解析。因此,如果 path2 包含空格(例如,“c:\”),Combine 方法 将 path2 附加到 path1 而不是只返回 path2。

    并非所有目录和文件名的无效字符都是 Combine 方法解释为不可接受,因为您可以使用 这些字符用于搜索通配符。例如,虽然 如果您要创建一个 Path.Combine("c:\", "*.txt") 可能无效 文件,它作为搜索字符串是有效的。因此是 由 Combine 方法成功解释。

    【讨论】:

    • 它说我没有声明“路径”,我需要做什么?无论如何,我需要在“ThisDir.Path \ checkedpath”之间加上一个斜杠,而不是合并,所以我认为你的例子对我不起作用......也许我已经磨损了,谢谢
    • 确保引用System.IOPath.Combine 将添加 /
    • 再次感谢,我的最终解决方案是:ControlChars.Quote & Path.Combine(ThisDir.Path, checkedpath1) & ControlChars.Quote
    【解决方案2】:

    试试这个:

    Process.Start(userSelectedFilePath, "\\" & ThisDir.Path & "\\" & checkedpath1 & "\\")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2018-09-09
      • 2011-11-11
      • 1970-01-01
      相关资源
      最近更新 更多