Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - escape character question - hopefully an easy question

Reply
 
Old 01-28-2009   #1 (permalink)
Cookiecutter


 
 

escape character question - hopefully an easy question

When a string with an escape character is enclosed in double quotes ( ie.
"k`[][][]") , the escape character is removed. With the given example, the
string becomes k[][][]. However, if it is enclosed in single quotes, it
retains the little 'tick'.

I'm working with ADO recordsets and fields of data from access databases
which are returned in the double-quote string format. Is there anyway I can
retain the 'tick' in this situation? I've tried "k`[][][]"
-replace('`','``'), but this does not seem to work. Is there a simple
solution?

My System SpecsSystem Spec
Old 01-29-2009   #2 (permalink)
RichS [MVP]


 
 

RE: escape character question - hopefully an easy question

I just tried this and it worked

PS> "k`[][][]"
k[][][]
PS> "k``[][][]"
k`[][][]

I don't think the replace will work as the single ` is lost as you build the
string
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Cookiecutter" wrote:
Quote:

> When a string with an escape character is enclosed in double quotes ( ie.
> "k`[][][]") , the escape character is removed. With the given example, the
> string becomes k[][][]. However, if it is enclosed in single quotes, it
> retains the little 'tick'.
>
> I'm working with ADO recordsets and fields of data from access databases
> which are returned in the double-quote string format. Is there anyway I can
> retain the 'tick' in this situation? I've tried "k`[][][]"
> -replace('`','``'), but this does not seem to work. Is there a simple
> solution?
My System SpecsSystem Spec
Old 01-29-2009   #3 (permalink)
RickB


 
 

Re: escape character question - hopefully an easy question

On Jan 28, 7:36*pm, Cookiecutter
<Cookiecut...@xxxxxx> wrote:
Quote:

> When a string with an escape character is enclosed in double quotes ( ie.
> "k`[][][]") , the escape character is removed. *With the given example,the
> string becomes *k[][][]. *However, if it is enclosed in single quotes, it
> retains the little 'tick'. *
>
> I'm working with ADO recordsets and fields of data from access databases
> which are returned in the double-quote string format. *Is there anyway I can
> retain the 'tick' in this situation? *I've tried "k`[][][]"
> -replace('`','``'), but this does not seem to work. *Is there a simple
> solution?
The reason your replace doesn't work is because the ` is already gone.
IOW it was never really in the string to begin with.
But if you have a string that contains the character then nothing
should remove it without you taking some explicit action.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: exchange shell escape character PowerShell
Escape character question PowerShell
How can I escape a slash character in item name? PowerShell
howto? escape the comment character PowerShell
Bug in escape character / variable expansion? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46