Skip to Main Content Skip to Search
Product Documentation

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

Create a 2-by-2 cell array in which each cell contains a word with trailing blanks:

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

Remove the trailing blanks and redisplay the cell array:

deblank(A);
A
A = 
    'MATLAB'       'SIMULINK'
    'Toolboxes'    'MathWorks'

See Also

strjust | strtrim

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS