REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: format

format  rules  values  /pad  p

Format a string according to the format dialect.

Arguments:

rules - A block in the format dialect. E.g. [10 -10 #"-" 4]

values

Refinements:

/pad

p

Description

This is useful for table output in the console, where fixed-width fonts are used. It can also be used to specially format numbers or complex values.

The first input, is the dialect. It's a combination of positive or negative formatting integers and strings or chars, that are to be inserted between the integers.

A positive integer N, means the value will be left adjusted with N chars for space.

A negative integer N, means the value will be right adjusted with N chars for space.

In both cases, a value that takes up more space than N, is truncated to N chars.

The second input is the values, either as a block or as a single value.

Example:

format [-3 -3 -4] [1 2 3]
"  1  2   3"

Format a time value using /pad to add zeroes:

format/pad [-2 ":" -2 ":" -2] [12 47 9] 0
"12:47:09"

It can also be used to pad zeroes to a single numeric value:

format/pad [-8] 5125 0
"00005125"


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin