deblank - Strip trailing blanks from end of string

Syntax

str = deblank(str)
c = deblank(c)

Description

str = deblank(str) removes all trailing whitespace and null characters from the end of character string str. A whitespace is any character for which the isspace function returns logical 1 (true).

c = deblank(c) when c is a cell array of strings, applies deblank to each element of c.

The deblank function is useful for cleaning up the rows of a character array.

Examples

Example 1 – Removing Trailing Blanks From a String

Compose a string str that contains space, tab, and null characters:

NL = char(0);    TAB = char(9);
str = [NL 32 TAB NL 'AB' 32 NL 'CD' NL 32 TAB NL 32];

Display all characters of the string between | symbols:

['|' str '|']
ans =
    |    AB  CD       |

Remove trailing whitespace and null characters, and redisplay the string:

newstr = deblank(str);

['|' newstr '|']
ans =
    |    AB  CD|

Example 2– Removing Trailing Blanks From a Cell Array of Strings

A{1,1} = 'MATLAB    ';
A{1,2} = 'SIMULINK    ';
A{2,1} = 'Toolboxes    ';
A{2,2} = 'The MathWorks    ';
A = 

    'MATLAB    '       'SIMULINK    '     
    'Toolboxes    '    'The MathWorks    '


deblank(A)
ans = 

    'MATLAB'           'SIMULINK'
    'Toolboxes'        'The MathWorks'

See Also

strjust, strtrim

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS