문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top