我有string
" DBCA"并希望在F#
let sortedString str =
...
printfn "%A" <| sortedString "DBCA" // "ABCD"
C#上的代码示例
String
.Concat(
_str
.OrderBy(ch => ch)
);
答案 0 :(得分:7)
open System
let sortedString (str : string) = str |> Seq.sort |> String.Concat
答案 1 :(得分:1)
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
我有这个解决方案,但上面的答案更好