I am using VS2010, C #, .NET 3.5 to generate Powershell scripts (ps1 files).
Then Powershell requires escape characters.
Any suggestions on this to develop a good method that avoids characters?
public static partial class StringExtensions { public static string FormatStringValueForPS(this string value) { if (value == null) return value; return value.Replace("\"", "`\"").Replace("'", "`'"); } }
Using:
var valueForPs1 = FormatStringValueForPS("My text with \"double quotes\". More Text"); var psString = "$value = \"" + valueForPs1 + "\";";
source share