title: WMI escape characters on string variable programatically
body: <p>i have this working query</p>
  
  <pre><code>ManagementObject pnpdevice = new ManagementObjectSearcher(String.Format(
  "select * from Win32_PnPEntity where DeviceID='{0}'",
  "USB\\\\VID_046D&amp;PID_C52B&amp;MI_00\\\\6&amp;48E0D58&amp;0&amp;0000")).First();
  </code></pre>
  
  <p>where i just realized that i needed to use quadruple slashes for one slash: two to escape in c#, two to escape in wmi.</p>
  
  <p>my problem is how to do this programmatically instead of by hand. typically i would of course use the <code>@</code> in front of the string to escape, so this works as well:</p>
  
  <pre><code>ManagementObject pnpdevice = new ManagementObjectSearcher(String.Format(
  "select * from Win32_PnPEntity where DeviceID='{0}'",
  @"USB\\VID_046D&amp;PID_C52B&amp;MI_00\\6&amp;48E0D58&amp;0&amp;0000")).First();
  </code></pre>
  
  <p>but how do i do that with a string variable?</p>
  
  <pre><code>ManagementObject pnpdevice = new ManagementObjectSearcher(String.Format(
  "select * from Win32_PnPEntity where DeviceID='{0}'",
  device["DeviceID"].ToString())).First();
  </code></pre>
  
  <p>this doesn't have any of the escapes i need, and fails as an invalid query. writing it <code>@device["DeviceID"].ToString()</code> does not work.</p>
  
  <p>any ideas? </p>