view m-toolbox/classes/+utils/@prog/strpad.m @ 45:a59cdb8aaf31
database-connection-manager
Merge
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Tue, 06 Dec 2011 19:07:22 +0100 (2011-12-06)
parents
f0afece42f48
children
line source
+ − 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