It seems as if there is no function in the standard library of type char -> string -> string
, which insert a char
in front of (or at the end of)
The code from @pad is what I would use, because I like to treat strings as immutable if possible. But I wouldn't use Char.escaped
; it's specialized for when you want the OCaml lexical representation of a character. So here's what you get if you make that change:
let prefix_char s c = String.make 1 c ^ s
let suffix_char s c = s ^ String.make 1 c
Update
In the years since this question was asked, OCaml has changed so that strings are immutable. Excellent.