[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Keep only one part of a string

user@domain.invalid

9/14/2006 11:22:00 PM

Hello, how to better write that : self.ident = self.ident[/0-9*/]

I'm pretty sure there is a String method that would keep only the first
match of the regex but I didn't found it in the String doc reference

Thanks
6 Answers

e

9/14/2006 11:43:00 PM

0

Zouplaz wrote:
> Hello, how to better write that : self.ident = self.ident[/0-9*/]
>
> I'm pretty sure there is a String method that would keep only the first
> match of the regex but I didn't found it in the String doc reference

ri String#slice, ri String#slice!

> Thanks


--
Posted via http://www.ruby-....

user@domain.invalid

9/15/2006 9:34:00 AM

0

le 15/09/2006 01:43, Eero Saynatkari nous a dit:
> Zouplaz wrote:
>> Hello, how to better write that : self.ident = self.ident[/0-9*/]
>>
>> I'm pretty sure there is a String method that would keep only the first
>> match of the regex but I didn't found it in the String doc reference
>
> ri String#slice, ri String#slice!
>
>> Thanks
>
>

Fine ! Thanks... About the same topic (Strings) I wonder how to replace
"REF:90 REFERAL".gsub!('REF:','')
by something else

I tried with .delete but

"REF:90 REFERAL".delete!("REF:") delete every R, E or F char in the string


How to use delete ?

Thanks in advance

Paul Lutus

9/15/2006 10:02:00 AM

0

Zouplaz wrote:

> le 15/09/2006 01:43, Eero Saynatkari nous a dit:
>> Zouplaz wrote:
>>> Hello, how to better write that : self.ident = self.ident[/0-9*/]
>>>
>>> I'm pretty sure there is a String method that would keep only the first
>>> match of the regex but I didn't found it in the String doc reference
>>
>> ri String#slice, ri String#slice!
>>
>>> Thanks
>>
>>
>
> Fine ! Thanks... About the same topic (Strings) I wonder how to replace
> "REF:90 REFERAL".gsub!('REF:','')
> by something else

What something else? Please say specifically what you want to accomplish.
Post an example string before you apply your desired remedy, and after.

>
> I tried with .delete but
>
> "REF:90 REFERAL".delete!("REF:") delete every R, E or F char in the string
>
>
> How to use delete ?

You are asking how to apply a particular solution, but without first stating
a problem. Maybe the problem is better solved using a different method.

--
Paul Lutus
http://www.ara...

user@domain.invalid

9/15/2006 10:07:00 AM

0

le 15/09/2006 12:01, Paul Lutus nous a dit:
> Zouplaz wrote:
>
>> le 15/09/2006 01:43, Eero Saynatkari nous a dit:
>>> Zouplaz wrote:
>>>> Hello, how to better write that : self.ident = self.ident[/0-9*/]
>>>>
>>>> I'm pretty sure there is a String method that would keep only the first
>>>> match of the regex but I didn't found it in the String doc reference
>>> ri String#slice, ri String#slice!
>>>
>>>> Thanks
>>>
>> Fine ! Thanks... About the same topic (Strings) I wonder how to replace
>> "REF:90 REFERAL".gsub!('REF:','')
>> by something else
>
> What something else? Please say specifically what you want to accomplish.
> Post an example string before you apply your desired remedy, and after.
>

Sorry, what I would like to know is if there is a another String method
to delete a part of a string instead of gsub

In the string "REF:90 REFERAL"

I want REF: to be deleted but not the REF or REFERAL

I've tried with the .delete method but each R, E F : char was deleted in
the string

MonkeeSage

9/15/2006 11:36:00 AM

0

Zouplaz wrote:
> Sorry, what I would like to know is if there is a another String method
> to delete a part of a string instead of gsub
>
> In the string "REF:90 REFERAL"
>
> I want REF: to be deleted but not the REF or REFERAL
>
> I've tried with the .delete method but each R, E F : char was deleted in
> the string

You want String#slice!

s = 'REF:90 REFERAL'
s.slice!('REF:') # => "REF:"
s # => "90 REFERAL"

Check out the core documentation for the String class:
http://ruby-doc.org/core/classes/S...

Regards,
Jordan

Logan Capaldo

9/15/2006 1:00:00 PM

0

On Fri, Sep 15, 2006 at 07:10:52PM +0900, Zouplaz wrote:
> le 15/09/2006 12:01, Paul Lutus nous a dit:
> >Zouplaz wrote:
> >
> >>le 15/09/2006 01:43, Eero Saynatkari nous a dit:
> >>>Zouplaz wrote:
> >>>>Hello, how to better write that : self.ident = self.ident[/0-9*/]
> >>>>
> >>>>I'm pretty sure there is a String method that would keep only the first
> >>>>match of the regex but I didn't found it in the String doc reference
> >>>ri String#slice, ri String#slice!
> >>>
> >>>>Thanks
> >>>
> >>Fine ! Thanks... About the same topic (Strings) I wonder how to replace
> >>"REF:90 REFERAL".gsub!('REF:','')
> >>by something else
> >
> >What something else? Please say specifically what you want to accomplish.
> >Post an example string before you apply your desired remedy, and after.
> >
>
> Sorry, what I would like to know is if there is a another String method
> to delete a part of a string instead of gsub
>
> In the string "REF:90 REFERAL"
>
> I want REF: to be deleted but not the REF or REFERAL
>
> I've tried with the .delete method but each R, E F : char was deleted in
> the string
s = "REF:90 REFERAL"
s.slice!("REF:")
s #=> "90 REFERAL"