[Haskell-cafe] How to print the " character without the backslash

Neil Mitchell ndmitchell at gmail.com
Mon May 29 13:05:49 EDT 2006


Hi

> I have this basic question of how to print the character " without
> the backslash.
>
> I'm trying to print html code, so i need " a lot.
>
>   giveHtml (Leaf (a,(b,c))) = "<frame src=\"\" name=\"" ++ [a] ++ "\"
> scrolling=\"No\" noresize=\"noresize\" id=\"" ++ [a] ++ "\" title=\""
> ++ [a] ++ "\" />"
>
> Can anybody give me a light here?
Yes, use the fact that HTML (and Javascript) both allow either " or '
as their string character.

>   giveHtml (Leaf (a,(b,c))) = "<frame src='' name='" ++ [a] ++ "'
> scrolling='No' noresize='noresize' id='" ++ [a] ++ "' title='"
> ++ [a] ++ "' />"

Less escape characters all round :)

You can even (if you wish) write a singleToDouble function that
replaced all ' with ", but its not necessary when generating HTML.

Thanks

Neil


More information about the Haskell-Cafe mailing list