my new defination is

$var="Tony said:"I like this game!""

It appeared that only

"Tony said:"

part can be recoginized, but I need the whole sentence. What can I do?

link|improve this question

feedback

3 Answers

up vote 4 down vote accepted

http://ss64.com/ps/syntax-esc.html

A simple solution is to just double the quotes. See the link for other options.

$var="Tony said:""I like this game!"""
link|improve this answer
Thank you very much. It works. – pansal Sep 7 '11 at 8:30
feedback

Just for completness, alternative solutions are to use the escape character:

$var= "Tony said:\`"I like this game!\`""

or "here strings" which are normally useful for multi-line texts but can be used for this case as well:

$var=@"
Tony said:"I like this game!"
"@
link|improve this answer
feedback

Even easier: single quotes. You can put any number of double quotes in a single-quote string, or vice versa:

 $var = 'Tony said, "I like this game!"'

or

 $var = "Tony said, 'I like this game!'"

I personally think this is the easiest and most readable solution.

link|improve this answer
2  
Worth noting that variables within single quotes will not be evaluated. – jscott Sep 9 '11 at 1:31
Good point. That's the fundamental difference between single and double quotes -- single quotes will treat all internal text literally, whereas double quotes will expand variables [or expressions enclosed in $()]. – jbsmith Sep 9 '11 at 16:30
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.