octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another implementation for strrep


From: Paul Kienzle
Subject: Re: Another implementation for strrep
Date: Sat, 10 Mar 2007 06:03:49 -0500


On Mar 10, 2007, at 4:10 AM, Thomas Treichl wrote:

function t = _strrep_ (s, x, y)

  if (nargin != 3), print_usage (); endif

  if (! (ischar (s) && ischar (x) && ischar (y)))
    error ("strrep: all arguments must be strings");
  endif

  t = regexprep (s, x, y);

endfunction


This isn't (yet) suitable for replacing strrep since the replacement argument x may have regular expression operators within it. You will need to escape them before applying the pattern. Something like the following might work:

  pattern = regexprep(x,'([*+([\\])','\\\1');
  t = regexprep(s,pattern,y);

You will have to look up the syntax of the regular expression to figure out exactly which characters are significant and how to do replacement strings.

Also, if you can easily gather your strings into a cell array, you should be
able to translate all of them at once and save even more time.

- Paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]