Home > atmlab > handy > strrep_multi.m

strrep_multi

PURPOSE ^

strrep_multi Perform multiple string replacement

SYNOPSIS ^

function s_new = strrep_multi(s_old, varargin)

DESCRIPTION ^

 strrep_multi Perform multiple string replacement

 For an input string s, perform many string replacements at once

 FORMAT

   s_new = strrep_multi(s_old, S)

 IN

   s_old   string      initial string
   s1      string      to be replaced
   s2      string      to replace with
   s3      ...         etc.

 OUT

   s_new   string      final string

 $Id: strrep_multi.m 6543 2010-10-07 15:57:41Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

strrep_multi.m

SOURCE CODE ^

0001 function s_new = strrep_multi(s_old, varargin)
0002 
0003 % strrep_multi Perform multiple string replacement
0004 %
0005 % For an input string s, perform many string replacements at once
0006 %
0007 % FORMAT
0008 %
0009 %   s_new = strrep_multi(s_old, S)
0010 %
0011 % IN
0012 %
0013 %   s_old   string      initial string
0014 %   s1      string      to be replaced
0015 %   s2      string      to replace with
0016 %   s3      ...         etc.
0017 %
0018 % OUT
0019 %
0020 %   s_new   string      final string
0021 %
0022 % $Id: strrep_multi.m 6543 2010-10-07 15:57:41Z gerrit $
0023 
0024 assert(mod(nargin, 2)==1, ...
0025     'atmlab:strrep_multi', ...
0026     'Number of input arguments must be odd');
0027 s_new = s_old;
0028 for i = 2:2:nargin
0029     s_new = strrep(s_new, varargin{i-1}, varargin{i});
0030 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005