From: Dossy Date: 2002-07-24T01:24:49+09:00 Subject: Re: Strings and member-operators On 2002.07.24, Dossy wrote: > On 2002.07.24, Tom Sawyer wrote: > > let me get this straight? is the original question how to strip a string > > and remove quotes? > > > > /^("?)(.*)\1$/.match(self)[2].strip > > > > this only does double quotes and its striping after the quotes removal. > > is that what's wanted? well, i'll assume so. what about without regexp? > > > > return str[1..-1].strip if str[0..0] + str[-1..-1] == '""' > > > > hmmm... you'd think there'd be a real simple way to do this without > > regexp, can it get any simpler? > > It's faster using regexp. Fewer intermediate temporary objects created. Oh, and your code doesn't work, either. It doesn't make all the tests pass: Loaded suite tc_ts_strip_quotes Started... .. Failure occurred in test_do_nothing(StripQuotesTest) [tc_ts_strip_quotes.rb:5]: Expected but was . Failure occurred in test_strip_doublequotes(StripQuotesTest) [tc_ts_strip_quotes.rb:9]: didn't remove outer double quotes. Expected but was . Failure occurred in test_strip_whitespace(StripQuotesTest) [tc_ts_strip_quotes.rb:20]: didn't strip trailing whitespace. Expected but was Finished in 0.00509 seconds. 3 runs, 3 assertions, 3 failures, 0 errors -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)