Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.1.0 - English


justify

Aligns the strings completed with spaces within each column, to the left, center or right

Syntax

TJ = justify(T, position)

Arguments

T, TJ

vectors, matrices or hypermatrices of strings, of same sizes.

position

Optional parameter, with one of the following values:

'l' or 'left' : left justification (default mode)
'c' or 'center': centering
'r' or 'right' : right justification

Description

All heading and trailing spaces of T elements are removed before processing.

In each given column of TJ, all strings have the same length. Shorter strings are padded with spaces before, after, or on both sides.

The width may differ from a column to other ones. Please see the examples

Examples

m = ["a" "bcdef" "ghi" ; "jklm" "" "n" ; "opq" "rs" "tuvwxy"]
justify(m)
justify(m, "r")
justify(m, "c")
--> m = ["a" "bcdef" "ghi" ; "jklm" "" "n" ; "opq" "rs" "tuvwxy"]
 m  =
  "a"     "bcdef"  "ghi"
  "jklm"  ""       "n"
  "opq"   "rs"     "tuvwxy"

--> justify(m)
 ans  =
  "a   "  "bcdef"  "ghi   "
  "jklm"  "     "  "n     "
  "opq "  "rs   "  "tuvwxy"

--> justify(m, "r")
 ans  =
  "   a"  "bcdef"  "   ghi"
  "jklm"  "     "  "     n"
  " opq"  "   rs"  "tuvwxy"

--> justify(m, "c")
 ans  =
  " a  "  "bcdef"  " ghi  "
  "jklm"  "     "  "  n   "
  "opq "  " rs  "  "tuvwxy"

See also

  • stripblanks — strips / trims leading or trailing or both blanks (and tabs) of strings
  • blanks — create string of blank characters
  • length — Number of characters of a string. Number of elements of an array or list.
  • part — Extraction of characters from strings

History

VersionDescription
2023.1 Hypermatrix accepted. The position becomes optional, with default = "left"
Report an issue
<< isnum Strings length >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon May 22 12:37:07 CEST 2023