Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Re: "ocaml_beginners"::[] string to list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Issac Trotts <ijtrotts@u...>
Subject: Re: [Caml-list] Re: "ocaml_beginners"::[] string to list
Christian Schaller wrote:

>Issac,
>
>Thanks a lot for this.  I am somewhat surprised, since this should be a
>built-in function.  Anyway, maybe you can help me with this one, too:  is
>there also a conversion from character to string or appending a character in
>front or at the end of a string?
>
>- Chris
>
Hi Chris,

Here's a way to make a string from a char:

# let c = 'a';;
val c : char = 'a'
# String.make 1 c;;
- : string = "a"

It's possible to prepend and append like this:

# (String.make 1 c) ^ "foo";;
- : string = "afoo"
# "foo" ^ (String.make 1 c);;
- : string = "fooa"

but it is probably more efficient to use the Buffer 
module (buffer.mli in /usr/lib/ocaml or 
/usr/local/lib/ocaml).

Issac







-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners