Reputation: 9130
So I have a simple question:
I want to insert " into ocaml string, like this:
let a = "this is \"good\" code";;
But it seems that using \ is not useful
I searched for a while but could not find anything useful..
Could anyone give me some help?
Upvotes: 1
Views: 355
Reputation: 66823
Your code is correct:
# let a = "this is \"good\" code";;
val a : string = "this is \"good\" code"
# String.length a;;
- : int = 19
# print_string a;;
this is "good" code- : unit = ()
#
Perhaps you're confused by the \
characters in the output. The OCaml toplevel is writing the string in lexical form; i.e., in the form it should appear in an OCaml program. The \
escapes are not part of the string, as the length and the print_string
show.
Upvotes: 2