Re: No way of looking for a regrexp match starting from a particular point in a string?
- From: "Robert Dober" <robert.dober@xxxxxxxxx>
- Date: Mon, 4 Jun 2007 21:06:28 +0900
On 6/4/07, Robert Klemme <shortcutter@xxxxxxxxxxxxxx> wrote:
On 04.06.2007 13:28, Robert Dober wrote:
Robert, actually string[n..-1] is cheaper than you might assume: II am afraid that this is not true anymore when the slice is passed as
believe the new string shares the char buffer with the old string, so
you basically just get a new String object with a different offset - the
large bit (the char data) is not copied.
a formal parameter, the data has to be copied :(
irb(main):011:0> def change(x)
irb(main):012:1> x << "changed"
irb(main):013:1> end
=> nil
irb(main):014:0> a="abcdef"
=> "abcdef"
irb(main):015:0> change(a[1..2])
=> "bcchanged"
irb(main):016:0> a
=> "abcdef"
Cheers
Robert
--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw
.
- Follow-Ups:
- References:
- No way of looking for a regrexp match starting from a particular point in a string?
- From: Kenneth McDonald
- Re: No way of looking for a regrexp match starting from a particular point in a string?
- From: Robert Dober
- Re: No way of looking for a regrexp match starting from a particular point in a string?
- From: Trans
- Re: No way of looking for a regrexp match starting from a particular point in a string?
- From: Robert Dober
- Re: No way of looking for a regrexp match starting from a particular point in a string?
- From: Robert Klemme
- No way of looking for a regrexp match starting from a particular point in a string?
- Prev by Date: newcocoa, command not found?
- Next by Date: Re: No way of looking for a regrexp match starting from a particular point in a string?
- Previous by thread: Re: No way of looking for a regrexp match starting from a particular point in a string?
- Next by thread: Re: No way of looking for a regrexp match starting from a particular point in a string?
- Index(es):
Relevant Pages
|