Home > m > helper > strpad.m

strpad

PURPOSE ^

STRPAD Pads a string with blank spaces until it is N characters long.

SYNOPSIS ^

function so = strpad(s, N)

DESCRIPTION ^

 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)

 INPUTS:     s  - string
             N  - length of the string

 OUTPUTS:    so - the padded string

 VERSION: $Id: strpad.html,v 1.14 2008/03/31 10:27:31 hewitson Exp $

 HISTORY: 27-04-2007 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function so = strpad(s, N)
0002 % STRPAD Pads a string with blank spaces until it is N characters long.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: STRPAD Pads a string with blank spaces until it is N characters
0007 %              long. If s is already N characters long (or longer) then the
0008 %              string is truncated.
0009 %
0010 % CALL:       so = strpad('Pads this string to 30 characters', 30)
0011 %
0012 % INPUTS:     s  - string
0013 %             N  - length of the string
0014 %
0015 % OUTPUTS:    so - the padded string
0016 %
0017 % VERSION: $Id: strpad.html,v 1.14 2008/03/31 10:27:31 hewitson Exp $
0018 %
0019 % HISTORY: 27-04-2007 M Hewitson
0020 %             Creation
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 while length(s) < N
0025   s = [s ' '];
0026 end
0027 
0028 so = s(1:N);
0029 
0030 
0031 % END

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003