Nuby - help on string spliting

Discussion in 'Ruby' started by Dany Cayouette, Sep 30, 2004.

  1. Any advice/ideas on the best way of attacking field split on ';' when the string looks like:

    s = 'a;b;c\;;d;'

    i.e. field delimiter is ';', and if ; appears in field data ; => \;

    Any regex magic? or should I use s.each_byte and do it by hand?

    Thanks,
    Dany
    Dany Cayouette, Sep 30, 2004
    #1
    1. Advertising

  2. Ignore this message... same question posted in comp.lang.ruby:71418


    On Thu, 30 Sep 2004 17:25:29 -0400
    Dany Cayouette <> wrote:

    > Any advice/ideas on the best way of attacking field split on ';' when the string looks like:
    >
    > s = 'a;b;c\;;d;'
    >
    > i.e. field delimiter is ';', and if ; appears in field data ; => \;
    >
    > Any regex magic? or should I use s.each_byte and do it by hand?
    >
    > Thanks,
    > Dany
    Dany Cayouette, Sep 30, 2004
    #2
    1. Advertising

  3. On Thursday 30 September 2004 23:40, Dany Cayouette wrote:
    > Any advice/ideas on the best way of attacking field split on ';' when the
    > string looks like:
    >
    > s = 'a;b;c\;;d;'
    >
    > i.e. field delimiter is ';', and if ; appears in field data ; => \;
    >
    > Any regex magic? or should I use s.each_byte and do it by hand?
    >



    hmmm.. your mail looks exactly like a mail I have replied to 2 minutes ago.
    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/114414


    something like this

    irb(main):023:0> "aa;bbb\\;;abc;;d\\\\;e;f".scan(/(?:\A|;)((?:\\[^.]|[^;])*)/)
    { p $1 }
    "aa"
    "bbb\\;"
    "abc"
    ""
    "d\\\\"
    "e"
    "f"
    => "aa;bbb\\;;abc;;d\\\\;e;f"
    irb(main):024:0>


    btw: are you solving some kind of exercise ?

    --
    Simon Strandgaard
    Simon Strandgaard, Sep 30, 2004
    #3

  4. >
    > btw: are you solving some kind of exercise ?
    >


    No. Mark introduced me to ruby. He's a programmer;I'm not! so I usually bounce questions off him. Got confused as I thought he was telling me to post to comp.lang.ruby, while he was actually posting himself. Sorry for the duplication...

    Dany
    Dany Cayouette, Sep 30, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    800
    Kevin Spencer
    Oct 27, 2003
  2. =?Utf-8?B?d3J5dGF0?=

    Problem converting string to int after spliting.

    =?Utf-8?B?d3J5dGF0?=, Jun 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    347
    =?Utf-8?B?d3J5dGF0?=
    Jun 7, 2005
  3. Sebek
    Replies:
    2
    Views:
    492
    Dimitre Novatchev [MVP XML]
    Apr 5, 2004
  4. stdazi
    Replies:
    3
    Views:
    655
  5. Stuart Clarke

    String spliting and inclusion

    Stuart Clarke, Jul 21, 2009, in forum: Ruby
    Replies:
    16
    Views:
    222
    Harry Kakueki
    Jul 23, 2009
Loading...

Share This Page