How do I sort strings alphabetically in F #?

I have a string

"DBCA" and want to sort it in F #

let sortedString str =
    ...

printfn "%A" <| sortedString "DBCA" // "ABCD"

      

Sample C # Code

String
    .Concat(
        _str
            .OrderBy(ch => ch)
    );

      

+3


source to share


2 answers


open System

let sortedString (str : string) = str |> Seq.sort |> String.Concat

      



+7


source


Solution with LINQ

open System
open System.Linq

let orderBy f xs = Enumerable.OrderBy(xs, new Func<_,_>(f))

let sortedString (str:string) =
    str 
    |> List.ofSeq
    |> orderBy (fun ch -> ch)
    |> String.Concat

      



I had this solution but above answer is better

+1


source







All Articles