1

我想我需要在這裏躲過特殊字符:VisualStudio中 - 如何擺脫這種字符

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

結果必須是這樣的:userselecfilepath「一blackquoted路徑\和其他文件夾」

什麼我做錯了?

三江源

UPDATE

解決方案:

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

回答

1
Process.Start(userSelectedFilePath, Path.Combine(ThisDir.Path, checkedpath)); 

Path.Combine

如果PATH1不是驅動基準(即, 「C:」 或 「d」),並且不具有有效 端如 DirectorySeparatorChar,AltDirectorySeparatorChar或 VolumeSeparatorChar中定義的分隔符字符,DirectorySeparatorChar在串聯之前附加到路徑1 。

如果PATH2不包括根目錄(例如,如果PATH2不與分隔符或驅動器規範開始 ),其結果是兩個路徑的 級聯,帶有分隔 字符。如果path2包含一個根,則返回path2。

如果參數有空白,則不會分析這些參數。因此,如果 path2包含空格(例如,「c:\」),則組合方法 會將path2附加到path1,而不是隻返回path2。

並非目錄和文件名稱的所有無效字符都是 被Combine方法解釋爲不可接受,因爲您可以使用 這些字符作爲搜索通配符。例如,如果您要從中創建 文件,則 Path.Combine(「c:\」,「* .txt」)可能無效,它作爲搜索字符串有效。因此,由Combine方法成功解釋了 。

+0

它說我沒有「路徑」聲明,我需要做什麼?無論如何,我需要在「ThisDir.Path \ checkedpath」之間加一個斜槓,而不是組合,所以我認爲你的例子不適合我...也許我worng,謝謝你 – ElektroStudios

+0

確保你參考'System.IO' 。 'Path.Combine'將添加到'/' – hunter

+0

再次感謝,我的最終解決方案是:ControlChars.Quote&Path.Combine(ThisDir.Path,checkedpath1)&ControlChars.Quote – ElektroStudios

1

試試這個:

的Process.Start(userSelectedFilePath, 「\\」 & ThisDir.Path &「\\ 「& checkedpath1 & 「\\」)

+0

對不起,不起作用 – ElektroStudios