how does one convert from a list of characters to a string?
To put it another way, how do I reverse List.ofSeq "abcd"
?
UPDATE: new System.String (List.ofSeq "abcd" |> List.toArray) |> printfn "%A"
seems to work fine, with or without new
, but List.ofSeq "abcd" |> List.toArray) |> new System.String |> printfn "%A"
fails. Why?
Use the valueOf() method in Java to copy char array to string. You can also use the copyValueOf() method, which represents the character sequence in the array specified. Here, you can specify the part of array to be copied.
I asked a similar question once before. It seems object constructors aren't composable so you can't pass them as a function.
List.ofSeq "abcd" |> List.toArray |> (fun s -> System.String s) |> printfn "%A" List.ofSeq "abcd" |> List.toArray |> (fun s -> new System.String(s)) |> printfn "%A"
Update Constructors are first-class functions as of F# 4.0
List.ofSeq "abcd" |> List.toArray |> System.String |> printfn "%A"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With