Formats a value based on a specific picture template.
Transform( <xExpression>, <cTemplate> ) --> cFormatted
<xExpression> Any expression to be formated.
<cTemplate> Character string with picture template
<cFormatted> Formatted expression in character format
This function returns <xExpression> in the format of the picture expression passed to the function as <cTemplate>.
Their are two components that can make up <cTemplate> : a function string and a template string. Function strings are those functions that globally tell what the format of <xExpression> should be. These functions are represented by a single character precede by the @ symbol.
There are a couple of rules to follow when using function strings and template strings:
– First, a single space must fall between the function template and the template string if they are used in conjunction with one another.
– Second, if both components make up the value of <cTemplate>, the function string must precede the template string. Otherwise, the function string may appear with out the template string and vice versa.
The table below shows the possible function strings available with the Transform() function.
@B Left justify the string within the format. @C Issue a CR after format is numbers are positive. @D Put dates in SET DATE format. @E Put dates in BRITISH format. @L Make a zero padded string out of the number. @R Insert non template characters. @X Issue a DB after format is numbers are negative. @Z Display any zero as blank spaces. @( Quotes around negative numbers @! Convert alpha characters to uppercased format.
The second part of <cTemplate> consists of the format string. Each character in the string may be formatted based on using the follow characters as template markers for the string.
A,N,X,9,# Any data type L Shows logical as "T" or "F" Y Shows logical as "Y" or "N" ! Convert to uppercase $ Dollar sing in place of leading spaces in numeric expression * Asterisks in place of leading spaces in numeric expression , Commas position . Decimal point position
LOCAL cString := "This is harbour" LOCAL nNumber := 9923.34 LOCAL nNumber1 := -95842.00 LOCAL lValue := .T. LOCAL dDate := Date() ? "working with String" ? "Current String is", cString ? "All uppercased", Transform( cString, "@!" ) ? "Date is", ddate ? "Date is ", Transform( ddate, "@D" ) ? Transform( nNumber, "@L 99999999" ) // "009923.34" ? Transform( 0 , "@L 9999" ) // "0000"
The @L function template is a FoxPro/Xbase++ Extension
Library is core