4 people like it.

A very cheeky string split operator

If we can concatenate strings with +, what would it mean to have a / operator?

1: 
2: 
3: 
4: 
let (/) (s : string) (sep : char) = s.Split(sep)

// [|"Apples"; "Oranges"; "Bananas"|]
"Apples,Oranges,Bananas" / ','
val s : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val sep : char
Multiple items
val char : value:'T -> char (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.char

--------------------
type char = System.Char

Full name: Microsoft.FSharp.Core.char
System.String.Split([<System.ParamArray>] separator: char []) : string []
System.String.Split(separator: string [], options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], count: int) : string []
System.String.Split(separator: string [], count: int, options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], count: int, options: System.StringSplitOptions) : string []

More information

Link:http://fssnip.net/7V3
Posted:2 months ago
Author:Kit Eason
Tags: #operators , #strings