On 26/6/09 08:06, Peter Alcibiades wrote:
I filed this to ask for 'replace' to have an additional option - to work like the Sed /s command. If you aren't familiar with this relic

s/oldtext/newtext/

will replace only the first occurrence of oldtext in a line. In all lines of the file, or the specified subset of the file.

s/oldtext/newtext/g

will replace all occurrences of oldtext in the file, or the specified subset. Probably the ability to specify subsets is not important any more, there are easy ways to get the same effect. But the ability to hit the first occurrence only in a line would be nice.

I'm sure this is not a super high priority for anyone, but it would be a nice addition to the string manipulation abilities, save having to roll one's own, and bring Rev closer to being a real Swiss Army knife.

I see your point, but (unless I've missed something) adding this in the engine wouldn't be much of an advantage over what we have. Eg adding an option to replace do only do the first occurence only replaces two lines:

  get offset(oldtext, x)
  if it > 0 then put newtext into char it to it + length(oldtext) - 1 of x

Adding the ability to do it by line only requires a few more

  put empty into z
  repeat for each line y in x
    get offset(oldtext, y)
    if it > 0 then put newtext into char it to it + length(oldtext) - 1 of y
    put y & return after z
  end repeat

... and that's remarkably fast in Transcript.


Not that it's a competition, but in a related area we're closing in on the 5th birthday of my request for backwards offset, which I'd argue was a more powerful addition, because it's a remarkably cumbersome thing to do in Transcript:

http://quality.runrev.com/qacenter/show_bug.cgi?id=584

Ben

_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to