title: Using a variable inside a CDATA string in VB.NET?
body: <p>Suppose that I have a Class with a multiline string like this:</p>
  
  <pre><code>Public Class HelpSection
  
      ' This process name (Example: 'MyProcess.exe')
      Public Shared ReadOnly ThisProcess As String = 
          Process.GetCurrentProcess().MainModule.ModuleName
  
      Public Shared ReadOnly Syntax As String = 
          &lt;a&gt;&lt;![CDATA[
              [+] Syntax:
  
                  ThisProcess (SWITCH)=(VALUE) (IN FILE)
          ]]&gt;&lt;/a&gt;.Value
  
  End Class
  </code></pre>
  
  <p>And now, when I call the multiline string: </p>
  
  <pre><code>Console.WriteLine(HelpSection4.Syntax)
  </code></pre>
  
  <p>It will print this:</p>
  
  <pre><code>ThisProcess (SWITCH)=(VALUE) (IN FILE)
  </code></pre>
  
  <p>But I would like to print automatically the <code>ThisProcess</code> variable content (the process name) like this:</p>
  
  <pre><code>MyProcess.exe (SWITCH)=(VALUE) (IN FILE)
  </code></pre>
  
  <p>So how I can manage the CDATA literal to set the variable content dynamically?</p>
  
  <p>Is this possibly?</p>
  
  <p>Maybe a better approach to manage this? (dynamically without hardcoding, keep in mind that it's for generic usage)</p>
  
  <blockquote>
    <p>UPDATE</p>
  </blockquote>
  
  <p>I'm trying to reproduce @<strong>Dan-o</strong> solution but of course in my case don't works because it's a CDATA literal, then how to escape it or do the necessary modifications?:</p>
  
  <pre><code>        Dim ProcessName As String = "MyProcess.exe"
  
          Dim Help As XElement =
  &lt;Help&gt;
      &lt;Process&gt;&lt;%= ProcessName %&gt;&lt;/Process&gt;
      &lt;Syntax&gt;&lt;a&gt;&lt;![CDATA[
  [+] Syntax:
  
      &lt;% ProcessName %&gt; (SWITCH)=(VALUE) (IN FILE)
  ]]&gt;&lt;/a&gt;&lt;/Syntax&gt;
  &lt;/Help&gt;
  
          Console.WriteLine(Help.&lt;Process&gt;.Value)
          Console.WriteLine(Help.&lt;Syntax&gt;.Value)
  </code></pre>
  
  <blockquote>
    <p>UPDATE 2</p>
  </blockquote>
  
  <p>In a simple XML file (for example, a .NET code snippet) I use this trick that I've learned time ago to scape a character in a CDATA:</p>
  
  <pre><code>&lt;Literal Editable="false"&gt;
      &lt;ID&gt;cdataend&lt;/ID&gt;
      &lt;ToolTip&gt;Part of the CDATA end tag.&lt;/ToolTip&gt;
      &lt;Default&gt;&amp;gt;&lt;/Default&gt;
  &lt;/Literal&gt;
  </code></pre>
  
  <p>Then I could write the <code>&gt;</code> illegal character inside, like this:</p>
  
  <pre><code>&lt;Code Language="vb"&gt;&lt;a&gt;&lt;![CDATA[ something ]]$cdataend$&lt;/a&gt;.Value ]]&gt;&lt;/Code&gt;
  </code></pre>
  
  <p>The thing is that I don't know if that can help me with the variable issue... just I'm trying to give ideas.</p>