[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Nuby - help on string spliting

Dany Cayouette

9/30/2004 9:25:00 PM

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
3 Answers

Dany Cayouette

9/30/2004 9:40:00 PM

0

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


On Thu, 30 Sep 2004 17:25:29 -0400
Dany Cayouette <danyc@nortelnetworks.com> 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

Simon Strandgaard

9/30/2004 9:45:00 PM

0

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-t...


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


Dany Cayouette

9/30/2004 10:00:00 PM

0


>
> 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