locked
How to split text by double pipe in F#? RRS feed

  • Question

  • How to split text by double pipe in F#?
    Thursday, June 20, 2013 6:29 AM

Answers

  • open System
    let splitby (text: string) = 
        text.Split([|"||"|], StringSplitOptions.None)
    

    You can use also another split option: StringSplitOptions.RemoveEmptyEntries

    Petr

    • Marked as answer by Opti4 Thursday, June 20, 2013 1:22 PM
    Thursday, June 20, 2013 12:12 PM

All replies

  • open System
    let splitby (text: string) = 
        text.Split([|"||"|], StringSplitOptions.None)
    

    You can use also another split option: StringSplitOptions.RemoveEmptyEntries

    Petr

    • Marked as answer by Opti4 Thursday, June 20, 2013 1:22 PM
    Thursday, June 20, 2013 12:12 PM
  • Thanks..Its working fine.

    But i also discoved one solution,that too worked fine.

    I replaced double pipe(||) by some other symbol i.e.^ and then split by this symbol.

    text.Replace("||","^").Split('^')

    Thursday, June 20, 2013 1:11 PM
  • It's fine if you have small string to split. Just keep in mind that each string operation creates new instance of string in memory because strings in .NET are immutable. So 'Replace' will create new string in memory. It can hurt if you have large amount of text and you care about performance


    Petr

    Thursday, June 20, 2013 1:19 PM
  • Ok.Got it.

    Your answer seems better for me.

    Thanks alot.


    Thursday, June 20, 2013 1:25 PM