Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Nuby - help on string spliting

Reply
Thread Tools

Nuby - help on string spliting

 
 
Dany Cayouette
Guest
Posts: n/a
 
      09-30-2004
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
 
Reply With Quote
 
 
 
 
Dany Cayouette
Guest
Posts: n/a
 
      09-30-2004
Ignore this message... same question posted in comp.lang.ruby:71418


On Thu, 30 Sep 2004 17:25:29 -0400
Dany Cayouette <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Simon Strandgaard
Guest
Posts: n/a
 
      09-30-2004
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...by-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


 
Reply With Quote
 
Dany Cayouette
Guest
Posts: n/a
 
      09-30-2004

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String spliting and inclusion Stuart Clarke Ruby 16 07-23-2009 09:13 AM
Spliting a string on non alpha characters stdazi Python 3 09-23-2006 10:10 PM
Problem converting string to int after spliting. =?Utf-8?B?d3J5dGF0?= ASP .Net 0 06-07-2005 04:16 AM
XSL : spliting string in an un identified number of sub-strings Sebek XML 2 04-05-2004 01:46 PM
spliting string by one of several characters? NEWBIE jason@cyberpine.com ASP .Net 2 10-27-2003 10:25 PM



Advertisments