justify Method

Class: ByteString

Description

This method returns a right justified form of its source that consists of at least the specified number of bytes.

Syntax

ByteString.justify(Number fieldlength)

Parameters

fieldLength

The length of the field to justify, specified as a number of bytes.

Returns

A ByteString of at least fieldLength bytes.

When Became Available

Profile V7.0

Example

type String     STR = "Knäckebröd" // contains 2 two-byte characters

type ByteString BST = STR.toByteString() // byte length = 12

//

// difference between byte length and character length: 2

type Number DIF1 = BST.length() - STR.length()

//

type ByteString BS1 = BST.justify( 8) // too short anyway

type ByteString BS2 = BST.justify(10) // still too short  (byte count!)

type ByteString BS3 = BST.justify(12) // exact ...

type ByteString BS4 = BST.justify(14) // now it makes a difference

//

// ByteString.justify() preserves character string

// Difference between byte length and character length not affected

type String OK = {String}BS4

type Number DIF2 = BS4.length() - OK.length()

//

if DIF1 '= DIF2 write "I don't understand ..."