Saturday, 7 September 2013

MultiLine string inside String.Format()?

MultiLine string inside String.Format()?

I'm trying to simplify some lines of code trying to assign a multiline
string in the string.format method but it throws an exception at the "< /
a >" characters it says "Expression expected":
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))
So if I can't do that then maybe I can do something similar string trick?
This is the original code I want to make it more readable in code:
' 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!")
I've tried too with a stringbuilder but I get a little bit unreadable code
that's why I've tried to put them all in a multiline string.

No comments:

Post a Comment