Split string by string in F#

时间:2016-10-09 15:52:10

标签: f#

In C# I could go like

data.Split(new string[] { "splitHere" }, StringSplitOptions.None);

I can't seem to get the same to work in F# or I may simply be doing it wrong (I just recently started to learn F#)

Update Just to clarify, my best attempt was

data.Split([", "], StringSplitOptions.None)

I'm fairly new to F# and moved from C#, so I make a number of noob errors still. On the up side, I couldn't find any info when searching for this subject, and now there's at least 1 :)

1 个答案:

答案 0 :(得分:4)

您可以按字符串分割字符串,如下所示:

open System
let colors = "red, green, blue"
let colorsArray = colors.Split([|", "|], StringSplitOptions.None)

,结果是

val colorsArray : string [] = [|"red"; "green"; "blue"|]