Skip to main content


abstract class %Library.Utility

Handy utility functions

Method Inventory


classmethod Center(str As %String = "", width As %Integer = 80) as %String
Center text on a line
classmethod Date(Format As %Integer = 7) as %String
Show the date, for example Sep 26 2003
classmethod DateTime(Format As %Integer = 7) as %String
Show date and time, for example: Sep 26 2003 5:39 PM
classmethod FormatMB(val As %Float) as %String
Used for formatting database and global sizes in MB Returns a minimum of two significant digits
classmethod FormatReference(reference As %String, Flags As %Integer = 1, ByRef overflow As %Boolean) as %String
FormatReference performs the same operations as FormatString, except the input is a local or global variable reference, in $NAME() format, and the formatting is applied separately to each subscript value.
classmethod FormatString(string As %String, Flags As %Integer = 1, ByRef overflow As %Boolean) as %String
Format a string, replacing unprintable characters with $C(nn) and showing $Lists with $LB(). $Bit strings are shown with $C() or $ZWC() and with a comment indicating which bits are set. %Status values are shown with $LB() and a comment describing the error.

Flags contains these options:
1 - Do the formatting with $C(), $LB(), and $ZWC(). If this bit is not set, the string is returned unchanged. The formatted value may be used in a SET command to reproduce the string.
2 - Add escape sequences to make the added formatting characters Bold.
4 - Write the formatted string to the current output device.
8 - Do not add a comment to $BIT() strings and %Status values.

The overflow argument is set to 1 if the formatted string has to be truncated because it is too long for a local variable.
classmethod Replace(Source As %String = "", FindWhat As %String = "", ReplaceWith As %String = "", MatchCase As %Boolean = 1, ByRef OutputString As %String, Start As %Integer = 1, RepeatCount As %Integer = 0, StartMode As %Integer = 0) as %Integer
Searches in Source the occurrences of FindWhat and replaces them with ReplaceWith.
The Search will be case insensitive if MatchCase=0 (default = 1).
The result of the operation will be placed in OutputString.
The method returns the number of times the replacement occurred.
You can also specify a starting point for the search (Start) and how many occurrences of
FindWhat you want replaced (default: 0 = All).
If FindWhat is the empty string, no replacement occurs. StartMode specifies how the Start parameter works. If StartMode=0, Start is a character count like in $Find. If StartMode=1, Start is a FindWhat count. That is, replacing starts at the beginning of the Start-th piece delimited by FindWhat. If Start<0, the find/replace operation works backwards from the end of the string. If Start is passed byref, return value of Start is where next search of the same line should start from, i.e. 1 character after the last replace.
classmethod Time() as %String
Show the time, for example 6:33 PM
FeedbackOpens in a new tab