Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@prog/strpad.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@prog/strpad.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,56 @@ +function varargout = strpad(varargin) +% STRPAD Pads a string with blank spaces until it is N characters long. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: STRPAD Pads a string with blank spaces until it is N characters +% long. If s is already N characters long (or longer) then the +% string is truncated. +% +% CALL: so = strpad('Pads this string to 30 characters', 30) +% so = strpad('Pads this string to 30 characters', [10 30]) +% so = strpad('Pads this string with = characters', [10 30], '=') +% +% INPUTS: s - string +% N - length of the string. If you give two values here, then +% the string is padded at the front and back. +% c - pad with this string/character. Default is ' '. +% +% OUTPUTS: so - the padded string +% +% VERSION: $Id: strpad.m,v 1.3 2008/08/19 15:43:15 hewitson Exp $ +% +% HISTORY: 27-04-2007 M Hewitson +% Creation +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +c = ''; +if nargin == 2 + s = varargin{1}; + N = varargin{2}; +elseif nargin == 3 + s = varargin{1}; + N = varargin{2}; + c = varargin{3}; +else + help(mfilename); + error('### Incorrect inputs'); +end + +if isempty(c) + c = ' '; +end + +if numel(N) == 2 + while length(s) < sum(N) + s = [c s c]; + end +else + while length(s) < N + s = [s c]; + end +end +% Set output +varargout{1} = s; +% END \ No newline at end of file