DDEBLANK Double deblank. Strip both leading and trailing blanks. DDEBLANK(S) removes leading and trailing blanks and null characters from the string S. A null character is one that has a value of 0. See also DEBLANK, DEWHITE, DDEWHITE.
0001 function sout = ddeblank(s) 0002 %DDEBLANK Double deblank. Strip both leading and trailing blanks. 0003 % 0004 % DDEBLANK(S) removes leading and trailing blanks and null characters from 0005 % the string S. A null character is one that has a value of 0. 0006 % 0007 % See also DEBLANK, DEWHITE, DDEWHITE. 0008 0009 % Author: Peter J. Acklam 0010 % Time-stamp: 2003-10-13 11:13:07 +0200 0011 % E-mail: pjacklam@online.no 0012 % URL: http://home.online.no/~pjacklam 0013 0014 error(nargchk(1, 1, nargin)); 0015 if ~ischar(s) 0016 warning('Input must be a string (char array).'); 0017 end 0018 0019 if isempty(s) 0020 sout = s; 0021 return; 0022 end 0023 0024 [r, c] = find( (s ~= ' ') & (s ~= 0) ); 0025 if size(s, 1) == 1 0026 sout = s(min(c) : max(c)); 0027 else 0028 sout = s(:, min(c) : max(c)); 0029 end