I have a model and source sequence. It is required to cut all occurrences of the model sequence in the original. The output is a sequence of sequences. The following are examples:

splitOn "x" "axbxc" = ["a","b","c"] splitOn "x" "axbxcx" = ["a","b","c",""] 

In other words, you need to implement an analogue of the Haskell function splitOn in C #.

Accordingly, I want to find an elegant solution to this problem. You can use the native approach with quadratic complexity, but I can not beautifully implement it in C # (I would like a more functional solution). Maybe there is a built-in function? Google on this issue is silent

PS The sequence may contain not only characters, but also other objects (for which the equal / not equal operation is defined)

  • string.Split('x') ? - ixSci
  • @ixSci, and if the objects are not only characters? - LmTinyToon

1 answer 1

For a string there is a method: string.Split . For the general case, for the collection, there is no such method - you need to write yourself. Or use MoreLINQ and use the ready-made Split method.

  • Quickly looked, there seems to be a sequence in the role of a separator - LmTinyToon
  • @AlexAkel, there are a lot of options, including delegates - you can customize as you please. - ixSci