Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escape code \" prints both \". Anyway to put a " in to a string.?

Tags:

string

haskell

let ans = stringConcat ["<a href=","\"",str,"\"",">",strr,"</a>"]
                putStr ("\nOutput :" ++show (ans))

when I print this answer is Output :"<a href=\"www.test.com\">testing</a>" I want to know why the extra \ is printing. \" suppose to be the escape code for double quotes. yet again it prints both \". I want to know why this happening and is there any way to put a " is side a string..?

concat function

stringConcat::[String]->String 
stringConcat xs= concat xs 
like image 740
Gihan Avatar asked Feb 07 '12 07:02

Gihan


2 Answers

Don't show a String.

let ans = stringConcat ["<a href=","\"",str,"\"",">",strr,"</a>"]
putStr ("\nOutput :" ++ ans)

Also, what is stringConcat?

like image 144
ivanm Avatar answered Oct 05 '22 02:10

ivanm


Yes, \" is the correct escape code for double quotes, so the string ans contains the double quotes as you expected.

The problem is that you're then using show, which is a function for showing values like they would appear in Haskell code, which means that strings with double quotes in them have to be escaped.

> putStrLn (show "I said \"hello\".")
"I said \"hello\"."

So if you don't want that, just don't use show:

> putStrLn "I said \"hello\"."
I said "hello".
like image 20
hammar Avatar answered Oct 05 '22 02:10

hammar