Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

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!"""
share|improve this answer
    
Thank you very much. It works. –  pansal Sep 7 '11 at 8:30
add comment

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!"
"@
share|improve this answer
add comment

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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