Logan
Logan

Reputation: 425

Split string by string in 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 :)

Upvotes: 2

Views: 3070

Answers (1)

Sousuke
Sousuke

Reputation: 1293

You can split string by string like this:

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

and the result is

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

Upvotes: 7

Related Questions