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.

strjust

Justify string or character array

Syntax

newTxt = strjust(txt)
newTxt = strjust(txt,side)

Description

example

newTxt = strjust(txt) returns a right-justified version of the text in txt.

  • If txt has trailing whitespace characters, then they become leading whitespace characters in newTxt.

  • If txt does not have trailing whitespace characters, then strjust returns txt unaltered.

example

newTxt = strjust(txt,side) returns a version of the text that is justified on the side specified by side. The text in txt can be justified on the left, right, or center.

Examples

collapse all

Create a string array in which some elements have trailing whitespace characters. Starting in R2017a, you can create strings using double quotes instead of the string function.

str1 = ["Skylab";
        "Mir   ";
        "ISS   "]
str1 = 3×1 string array
    "Skylab"
    "Mir   "
    "ISS   "

Justify the text on the right. strjust does not alter the first element because "Skylab" has no whitespace.

str2 = strjust(str1)
str2 = 3×1 string array
    "Skylab"
    "   Mir"
    "   ISS"

Create a cell array of character vectors. Some of the character vectors have leading and trailing whitespace characters.

C1 = {'Euler    ';
      'Fibonacci';
      '    Gauss'}
C1 = 3×1 cell array
    'Euler    '
    'Fibonacci'
    '    Gauss'

Center-justify the text. If a piece of text has leading or trailing whitespace, or both, then strjust adjusts the text to have an equal number of leading and trailing whitespace characters. strjust does not alter a piece of text when it has neither leading nor trailing whitespace.

C2 = strjust(C1,'center')
C2 = 3×1 cell array
    '  Euler  '
    'Fibonacci'
    '  Gauss  '

Input Arguments

collapse all

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

Data Types: char | cell | string

Side to justify text on, specified as 'left', 'right', or 'center'. The default behavior is to justify the text on the right.

Data Types: char | string

Extended Capabilities

Introduced before R2006a

Was this topic helpful?