我正在尝试简化一些代码行,试图在 string.format 方法中分配多行字符串,但它会在显示“预期表达式”的“</a>”字符处引发异常:
Dim RegistryScript As String = String.Format(<![CDATA[
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Environment]
"PATH"="{0}"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"PATH"="{1}"
]]></a>.Value, String.Join(";", PATH_Current), String.Join(";", PATH_Local))
所以如果我不能这样做,那么也许我可以做一些类似的字符串技巧?
这是我想让它在代码中更具可读性的原始代码:
' Current user
IO.File.WriteAllText(FilePath, " Windows Registry Editor Version 5.00" & Environment.NewLine, System.Text.Encoding.Unicode)
IO.File.AppendAllText(FilePath, "[HKEY_CURRENT_USER\Environment]" & Environment.NewLine, System.Text.Encoding.Unicode)
IO.File.AppendAllText(FilePath, String.Format("""PATH""=""{0}""", String.Join(";", PATH_Current)) & Environment.NewLine, System.Text.Encoding.Unicode)
' Local Machine
IO.File.AppendAllText(FilePath, " Windows Registry Editor Version 5.00" & Environment.NewLine, System.Text.Encoding.Unicode)
IO.File.AppendAllText(FilePath, "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]" & Environment.NewLine, System.Text.Encoding.Unicode)
IO.File.AppendAllText(FilePath, String.Format("""PATH""=""{0}""", String.Join(";", PATH_Local)) & Environment.NewLine, System.Text.Encoding.Unicode)
Console.WriteLine(" [+] Backup done!")
我也尝试过使用字符串生成器,但是我得到了一些不可读的代码,这就是为什么我尝试将它们全部放在多行字符串中的原因。