使用F#中的System.String.Split

Jon*_*ats 7 f# f#-3.0

我想在F#中使用.NET CLR版本的String.Split.具体来说我想使用这段代码:

let main argv = 
    let s = "Now is the time for FOO good men to come to the aide of their country"
    let sepAry = [|"FOO"; "BAR"|]
    let z1 = s.Split sepAry
    0 // return an integer exit code
Run Code Online (Sandbox Code Playgroud)

然而,由于(我相信)F#中的Split版本的实现方式与.Net 4.5中的版本不同,因此无法编译.我想要的.NET版本是:

Split(String [],StringSplitOptions)返回一个字符串数组,该数组包含此字符串中的子字符串,这些子字符串由指定字符串数组的元素分隔.参数指定是否返回空数组元素.

我知道我得到的是F#版本的Split,以前存在于PowerPack中,这就是为什么实现与CLR版本不同的原因.

得到我想要的最好的方法是什么?是否可以覆盖F#版本的Split并使用.Net版本?是否有可能扩展F#版本,如果是这样,如何?

kir*_*gin 7

您想要使用的重载需要第二个参数.

let z1 = s.Split (sepAry, System.StringSplitOptions.None)
Run Code Online (Sandbox Code Playgroud)

它不是"F#版本Split",它正是Split你在C#中看到的.