F#, Split String and .Net methods

You call them as instance methods:

let Count (text : string) =
  let words = text.Split [|' '|]
  let nWords = words.Length
  (nWords)

(Note you need to use [| |] because Split takes an array not a list; or, as per Joel Mueller’s comment, because Split takes a params array, you can just pass in the delimiters as separate arguments (e.g. text.Split(' ', '\n')).)

Leave a Comment