[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Wish list for 2.0

STEPHEN BECKER I V

9/28/2004 3:44:00 AM

In ref to http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...


A deletew or rmwhite where it deletes all the white space from a string
If you can use delete(/s) or something PLEASE let me know! :)

Becker


17 Answers

Yukihiro Matsumoto

9/28/2004 3:56:00 AM

0

Hi,

In message "Re: Wish list for 2.0"
on Tue, 28 Sep 2004 12:44:07 +0900, STEPHEN BECKER I V <Becker004@gmail.com> writes:

|A deletew or rmwhite where it deletes all the white space from a string
| If you can use delete(/s) or something PLEASE let me know! :)

str.delete(" ")

matz.


STEPHEN BECKER I V

9/28/2004 4:01:00 AM

0

does that work for end lines in the middle of a string? or a tab? I
mean all white space..


On Tue, 28 Sep 2004 12:56:21 +0900, Yukihiro Matsumoto
<matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Wish list for 2.0"
> on Tue, 28 Sep 2004 12:44:07 +0900, STEPHEN BECKER I V <Becker004@gmail.com> writes:
>
> |A deletew or rmwhite where it deletes all the white space from a string
> | If you can use delete(/s) or something PLEASE let me know! :)
>
> str.delete(" ")
>
> matz.
>
>


Phlip

9/28/2004 4:11:00 AM

0

STEPHEN BECKER I V wrote:

> does that work for end lines in the middle of a string? or a tab? I
> mean all white space..

What's wrong with str.gsub!(/\s/, ''), or similar ?

(I clicked looking for a wish list. I can't think of anything either...)

--
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUser...


Yukihiro Matsumoto

9/28/2004 4:40:00 AM

0

Hi,

In message "Re: Wish list for 2.0"
on Tue, 28 Sep 2004 13:01:24 +0900, STEPHEN BECKER I V <Becker004@gmail.com> writes:

|does that work for end lines in the middle of a string? or a tab? I
|mean all white space..

str.delete(" \n\t")

if you wish.

matz.


Gavin Sinclair

9/28/2004 6:45:00 AM

0

On Tuesday, September 28, 2004, 2:40:02 PM, Yukihiro wrote:

> Hi,

> In message "Re: Wish list for 2.0"
> on Tue, 28 Sep 2004 13:01:24 +0900, STEPHEN BECKER I V <Becker004@gmail.com> writes:

> |does that work for end lines in the middle of a string? or a tab? I
> |mean all white space..

> str.delete(" \n\t")

> if you wish.

Perhaps String#delete could take a regex as well?

str.delete /\s/

Gavin





Yukihiro Matsumoto

9/28/2004 7:45:00 AM

0

Hi,

In message "Re: Wish list for 2.0"
on Tue, 28 Sep 2004 15:45:29 +0900, Gavin Sinclair <gsinclair@soyabean.com.au> writes:

|Perhaps String#delete could take a regex as well?
|
| str.delete /\s/

Interesting idea. What if pattern match overwrap, e.g.

str = "aabab"
str.delete(/a./)

? Should it work as str.gsub(pat, "") ?

matz.


Brian Candler

9/28/2004 8:23:00 AM

0

> A deletew or rmwhite where it deletes all the white space from a string
> If you can use delete(/s) or something PLEASE let me know! :)

str = " abc def \n ghi jkl "
str.gsub!(/\s+/,'')
p str
# prints "abcdefghijkl"

You can define this as your own String#deletew method easily enough if you
need to use it over and over again:

class String
def deletew!
gsub!(/\s+/,'')
end
def deletew
dup.deletew!
end
end

Regards,

Brian.


Gavin Sinclair

9/28/2004 9:27:00 AM

0

On Tuesday, September 28, 2004, 5:45:08 PM, Yukihiro wrote:

> |Perhaps String#delete could take a regex as well?
> |
> | str.delete /\s/

> Interesting idea. What if pattern match overwrap, e.g.

> str = "aabab"
> str.delete(/a./)

> ? Should it work as str.gsub(pat, "") ?

That makes sense. Might as well implement it like that so it can be
documented as such.

Gavin




Simon Strandgaard

9/28/2004 9:00:00 PM

0

On Tuesday 28 September 2004 11:26, Gavin Sinclair wrote:
> On Tuesday, September 28, 2004, 5:45:08 PM, Yukihiro wrote:
> > |Perhaps String#delete could take a regex as well?
> > |
> > | str.delete /\s/
> >
> > Interesting idea. What if pattern match overwrap, e.g.
> >
> > str = "aabab"
> > str.delete(/a./)
> >
> > ? Should it work as str.gsub(pat, "") ?
>
> That makes sense. Might as well implement it like that so it can be
> documented as such.


Maybe model the behavior after #scan, so that it deletes the matches that scan
would have found. This way we can get very flexible deletion in case
captures are being used.

I propose #delete to erase those fragments that #scan matches.

irb(main):011:0> 'a12bc34de56fg78hi'.scan(/(\d).{2,}?(\d)/)
=> [["1", "3"], ["4", "5"], ["6", "7"]]
irb(main):012:0> 'a12bc34de56fg78hi'.scan(/\d.{2,}?\d/)
=> ["12bc3", "4de5", "6fg7"]
irb(main):013:0>


Lets change above 2 scan statements into delete

irb(main):011:0> 'a12bc34de56fg78hi'.delete(/(\d).{2,}?(\d)/)
=> "a2bcdefg8hi"
irb(main):012:0> 'a12bc34de56fg78hi'.delete(/\d.{2,}?\d/)
=> "a8hi"
irb(main):013:0>


Ok.. this is not the most obvious example.. but I hope you get the point.
Otherwise please ask :-)

--
Simon Strandgaard



STEPHEN BECKER I V

9/30/2004 6:31:00 PM

0

how about isprime, nextprime, preprime?