Reputation: 2536
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
Upvotes: 9
Views: 9375
Reputation: 139890
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".
Upvotes: 19
Reputation: 3927
Don't show
a String.
let ans = stringConcat ["<a href=","\"",str,"\"",">",strr,"</a>"]
putStr ("\nOutput :" ++ ans)
Also, what is stringConcat
?
Upvotes: 7
Reputation: 1011
why don't you try this
let ans = stringConcat ["<a href=","'",str,"'",">",strr,"</a>"]
Upvotes: 1