view m-toolbox/classes/+utils/@prog/strpad.m @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents f0afece42f48
children
line wrap: on
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