home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / STRFUN.DI$ / DEBLANK.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  664 b   |  30 lines

  1. function s1 = deblank(s)
  2. %DEBLANK Strip trailing blanks from end of a string.
  3. %    DEBLANK(S) removes the trailing blanks and any null characters from
  4. %    the string S.  A null character is one that has an absolute value of 0.
  5.  
  6. %    L. Shure, 6-17-92.
  7. %       Copyright (c) 1984-93 by The MathWorks, Inc.
  8.  
  9. if ~isstr(s)
  10.     error('Input must be a string.')
  11. end
  12.  
  13. if isempty(s)
  14.     s1 = s;
  15.     return;
  16. end
  17.  
  18. % first remove trailing blanks
  19. b = ' ';
  20. ns = length(s);
  21. nbc = min(find(fliplr(s) ~= b));
  22. if isempty(nbc)
  23.     s1 = '';
  24.     return
  25. end
  26. s1 = s(1:(length(s)-nbc(1)+1));
  27.  
  28. % remove any null characters (null character ==> abs(s) == 0)
  29. s1(find(abs(s)==0)) = [];
  30.