How to handle escape character (`) in string under PowerShell -
i using powershell read string , xml file cdata sectiona , contains powershell esacpe character (`) part of string content. when powershell reading , writing content, removing escape character , causing problems in usage of same content.
i not able add double escape sequence `` in input since provided user , cannot restrict user same.
how processed correctly powershell?
i can't reproduce problem. need more information.
test.xml
<?xml version="1.0" encoding="iso-8859-1"?> <exampleofacdata> <![cdata[ graimer`s [cdata[]] test. notice used backtick in text, powershell's escape character. i'm gonna store in `$s` in ps. ]]> </exampleofacdata>
powershell
ps > $xml = [xml](get-content .\desktop\test.xml) $s = $xml.exampleofacdata."#cdata-section" $s graimer`s [cdata[]] test. notice used backtick in text, powershell's escape character. i'm gonna store in `$s` in ps.
in general, make sure special characters behave normal characters, variables don't expand etc., use single quotes 'text'
around string. powershell's normal behaviour when strings other sources(functions, files ...) too.
Comments
Post a Comment