Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

deblank

Remove trailing whitespace from end of string or character array

Syntax

Description

example

newTxt = deblank(txt) removes trailing whitespace and null characters from txt and returns the result as newTxt. However, deblank does not remove significant whitespace characters. For example, deblank removes trailing space and tab characters, but does not remove the nonbreaking space character, char(160).

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

Examples

collapse all

Create a character vector that contains space, tab, and null characters.

chr = sprintf(' \t MathWorks \t');
chr = [chr char(0)];

Display chr between | characters.

['|' chr '|']
ans =

| 	 MathWorks 	 |

Remove the trailing blanks and display newChr between | characters.

newChr = deblank(chr);
['|' newChr '|']
ans =

| 	 MathWorks|

Starting in R2016b, you can create string arrays with the string function, and remove trailing whitespace with the deblank function.

str = string({'Gemini    ','Apollo    ';
              'ISS       ','Skylab    '})
str = 

  2×2 string array

    "Gemini    "    "Apollo    "
    "ISS       "    "Skylab    "

newStr = deblank(str)
newStr = 

  2×2 string array

    "Gemini"    "Apollo"
    "ISS"       "Skylab"

Remove trailing blanks from all the character vectors in a cell array and display them.

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

  2×2 cell array

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

B = deblank(A)
B =

  2×2 cell array

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

Create a character vector that includes the nonbreaking space character, char(160), as a trailing blank character.

chr = '     MathWorks';
chr = [chr char(160) '     '];

Display chr between | symbols to show the leading and trailing whitespace.

['|' chr '|']
ans =

|     MathWorks      |

Remove the trailing whitespace characters.

newChr = deblank(chr);

Display newChr between | symbols. deblank removes the trailing space characters, but leaves the nonbreaking space at the end of newChr.

['|' newChr '|']
ans =

|     MathWorks |

Input Arguments

collapse all

Input text, specified as a string array, a character array, or as a cell array of character arrays.

Data Types: string | char | cell

More About

collapse all

Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

Algorithms

deblank does not remove significant whitespace characters.

This table shows the most common characters that are significant whitespace characters and their descriptions. For more information, see Whitespace character.

Significant Whitespace Character

Description

char(133)

Next line

char(160)

Nonbreaking space

char(8199)

Figure space

char(8239)

Narrow no-break space

See Also

| | |

Introduced before R2006a

Was this topic helpful?