Formatters

By Kevin Schreiner

March 18, 2009

The FORMATTER option is defined by the syntax provided within the .Net Framework. The syntax was created and is provided in such a way as to work as a culture specific syntax. All format tokens begin and end with a curly brace {...}. Utilization of the format element can be simplistic, or provide a compound and deterministic statement which is much more advanced. After reviewing the options provided, a more advanced format provides the ability to vary the format depending on the value of the data. For example

{0:$#,##0.00;($#,##0.00);Nothing}

This syntax is usefull in combination with the following tags:

  • Format - [Format,Value,{FORMATTER}]
  • Pre Format - [$Value,{FORMATTER}]
  • COALESCE - [COALESCE,Value,Collection,{FORMATTER}]


The resulting output would be $1,234.50 if the data value was 1234.50. Or, ($1,234.50) if the value had been negative. If the item is zero, the output would result in Nothing.

(Show) Table of Contents

Standard .Net Formatters


Standard Numeric Formatting

Specifier
Type
FORMAT

Sample (1.2345)

Sample (-12345)

d
decimal
{0:d}
FormatException
-12345
e

exponent / scientific

{0:e}
1.234500e+000
-1.234500e+004
f

fixed point

{0:f}
1.23
-12345.00
g
general
{0:g}
1.2345
-12345
n
number
{0:n}
1.23
-12,345.00
r

round trippable

{0:r}
1.23
FormatException
x
hexadecimal
{0:x4}
FormatException
ffffcfc7

Custom Numeric Formatting

Specifier
Type
FORMAT

Sample (1234.56)

0

zero placeholder

{0:00.000}
1234.560
#

digit placeholder

{0:#.##}
1234.56
.

decimal point placeholder

{0:0.0}
1234.6
,

thousand separator

{0:0,0}
1,235
%
percentage
{0:0%}
123456

Standard Date Formatting

Specifier
Type
FORMAT

Sample (January 2, 3456 7:08:09 PM)

d
short date
{0:d}
1/2/3456
D
long date
{0:D}
Wednesday, January 2, 3456
t
short time
{0:t}
7:08 PM
T
long time
{0:T}
7:08:09 PM
f

full date/time

{0:f}
Wednesday, January 2, 3456 7:08 PM
F

long full date/time

{0:F}
Wednesday, January 2, 3456 7:08:09 PM
g
general
{0:g}
1/2/3456 7:08 PM
G

long general

{0:G}
1/2/3456 7:08:09 PM
M

day / month

{0:M}
January 1
r

RFC1123 date

{0:r}
Wed, 1 Jan 3456 19:08:09 GMT
s

sortable date/time

{0:s}
3456-01-02T19:08:09
u
universal
{0:u}
3456-01-02 19:08:09Z
Y
month/year
{0:Y}
January, 3456

 

Custom Date Formatting

Specifier
Type
FORMAT

Sample (January 2, 3456 7:08:09 PM)

dd
day
{0:dd}
02
ddd
short day
{0:ddd}
Wed
dddd
long day
{0:dddd}
Wednesday
hh

2 digit hour

{0:hh}
07
HH

2 digit hour

{0:HH}
19
mm

2 digit minute

{0:mm}
08
MM
month
{0:MM}
01
MMM

short month name

{0:MMM}
Jan
MMMM

long month name

{0:MMMM}
January
ss
seconds
{0:ss}
09
tt
am/pm
{0:tt}
PM
yy

2 digit year

{0:yy}
56
yyyy

4 digit year

{0:yyyy}
3456
:
separator
{0:hh:mm:ss}
07:08:09
/
separator
{0:dd/MM/yyyy}
01/02/3456

 

Extended Formatters


While the standard .Net formatters provide the ability to handle most any type of generic data type, and layout the data precisely how you want it to appear, it doesn’t provide the facility to enhance your abilities to format the data in an “as you see fit” scenario.

Open Web Studio provides an enhanced FORMAT library with a variety of additional values which are identified in the following list. These formatters provide simple tasks like specific Tab look-ups by the Name of the tab, through advanced dynamic look-ups against any specific table to encoding, decoding and runtime verifications.

String Manipulation Formatters


LEFT


Used to return only the first N characters from the value

Format:
[FORMAT,VALUE,{LEFT:LENGTH }]

Example:
[FORMAT,My Tab,{LEFT:2}]

Result:
My

RIGHT


Used to return only the last N characters from the value

Format:
[FORMAT,VALUE,{RIGHT:LENGTH }]

Example:
[FORMAT,My Tab,{RIGHT:2}]

Result:
ab

MID


Used to return the characters from the middle of the value starting at character X and ending at character Y.

Format:
[FORMAT,VALUE,{MID:FROM,TO}]

Example:
[FORMAT,My Tab,{MID:3,5}]

Result:
Ta

 

UPPER


Convert the entire value to upper case

Format:
[FORMAT,VALUE,{UPPER}]

Example:
[FORMAT,My Tab,{UPPER}]

Result:
MY TAB

LOWER


Convert the entire value to lower case

Format:
[FORMAT,VALUE,{LOWER}]

Example:
[FORMAT,My Tab,{LOWER}]

Result:
my tab

LENGTH


Return the length of the value

Format:
[FORMAT,VALUE,{LENGTH}]

Example:
[FORMAT,My Tab,{LENGTH}]

Result:
6

REPLACE


Replace a specific character combination from the value with another. This can be used for any displayed or whitespace value. Additionally, special characters and symbols can be replaced by utilizing the char(#) syntax as the value for the LOOKFOR and/or the REPLACEWITH.

Format:
[FORMAT,VALUE,{REPLACE:LOOKFOR,REPLACEWITH}]
[FORMAT,VALUE,{REPLACE:char(LOOKFOR ASCII CODE),char(REPLACEWITH ASCII CODE)}]

Example:
[FORMAT,My Tab,{REPLACE:My,Our}]
[FORMAT,This is a 'test' value,{replace:char(39),---}]
[FORMAT,This is a 'test' value,{replace:char(39),char(34)}]

Result:
Our Tab
This is a ---test--- value
This is a "test" value

PADLEFT


Add a specific character to the Left of the value to reach a specific length for the entire text

Format:
[FORMAT,VALUE,{PADLEFT:LENGTH,CHARACTER}]

Example:
[FORMAT,My Tab,{PADLEFT:10,#}]

Result:
####My Tab

PADRIGHT


Add a specific character to the Right of the value to reach a specific length

Format:
[FORMAT,VALUE,{PADRIGHT:LENGTH,CHARACTER}]

Example:
[FORMAT,My Tab,{PADRIGHT:10,#}]

Result:
My Tab####

TRIM


Remove whitespace characters from the Left and Right of the value

Format:
[FORMAT,VALUE,{TRIM}]

Example:
([FORMAT,”   My Tab   ”,{TRIM}])

Result:
(My Tab)

TRIMLEFT


Remove whitespace characters from the Left of the value

Format:
[FORMAT,VALUE,{TRIMLEFT}]

Example:
([FORMAT,”   My Tab   ”,{TRIMLEFT}])

Result:
(My Tab   )

 

TRIMRIGHT


Remove whitespace characters from the Right of the value

Format:
[FORMAT,VALUE,{TRIMRIGHT}]

Example:
([FORMAT,”   My Tab   ”,{TRIMRIGHT}])

Result:
(   My Tab)

Encoding, Decoding


ENCODEURI


Convert the value to a ANSI standard URI formatted value for query string pass through from a real ASCII value

Format:
[FORMAT,VALUE,{ENCODEURI}]

Example:
([FORMAT,”!@#$ %^&*()<>=&”,{ENCODEURI}])

Result:
!%40%23%24+++%25%5e%26*()%3c%3e%3d%26

DECODEURI


Convert the value from the ANSI standard URI formatted query string value to a real ASCII value

Format:
[FORMAT,VALUE,{DECODEURI}]

Example:
([FORMAT,”!%40%23%24+++%25%5e%26*()%3c%3e%3d%26”,{DECODEURI}])

Result:
!@#$ %^&*()<>=&

ENCODEHTML


Convert the ASCII value containing HTML formatting to a standard, non-HTML handled format. In real terms, replacing the HTML formatting with escaped HTML formatting, for example: ‘<’ becomes ‘&lt;’.

Format:
[FORMAT,VALUE,{ENCODEHTML}]

Example:
([FORMAT,”<li>This is a test & it works</li>”,{ENCODEHTML}])

Result:
&lt;li&gt;This is a test &amp; it works &lt;/li&gt;
 

DECODEHTML


Convert the escaped HTML format with the true ASCII value, for example: ‘&lt;’ becomes ‘<’.

Format:
[FORMAT,VALUE,{ DECODEHTML}]

Example:
([FORMAT,”&lt;li&gt;This is a test &amp; it works &lt;/li&gt;”,{DECODEHTML}])

Result:
<li>This is a test & it works</li>

ENCODEWIKI


Using any standard value, automatically replace Wiki Syntax with the translated value. This is very useful for generic links, formatting and interaction for all types of data.

Format:
[FORMAT,VALUE,{ENCODEWIKI}]

Example:

([FORMAT,”[[Wiki|Wiki Syntax]]”,{ENCODEWIKI}])


Result:
<a href="?topic=Wiki">Wiki Syntax</a>

ENCRYPT


At times you may require the ability to Encrypt your value using a specific Key value for the encryption itself. To do this, use the Encrypt formatter with the desired Key as the parameter.

Format:
[FORMAT,VALUE,{ENCRYPT:KEY}]

Example:
([FORMAT,”<li>This is a test & it works</li>”,{ENCRYPT:12341253214321FA}])

Result:
JSFhfhiapfahpifwPIip2ip5fip%

DECRYPT


At times you may require the ability to Decrypt your value using a specific Key value for the decryption itself. To do this, use the Decrypt formatter with the desired Key as the parameter.

Format:
[FORMAT,VALUE,{DECRYPT:KEY}]

Example:
([FORMAT,”JSFhfhiapfahpifwPIip2ip5fip%”,{DECRYPT:12341253214321FA}])

Result:
<li>This is a test & it works</li>


Runtime Verification and Validation


ISEMPTY


Evaluate the value to determine if the value is empty, having a length of zero. In which case, a default value can be utilized in its place.

Format:
[FORMAT,VALUE,{ISEMPTY:DEFAULT}]

Example:
([FORMAT,”My Tab”,{ISEMPTY:No Tab Name provided }])
([FORMAT,””,{ISEMPTY:No Tab Name provided }])

Result:
My Tab
No Tab Name provided
 

ISINROLE


Returns a Boolean True or False value, identifying whether the current user is a member of a specific role (by name or id).
Note: Super Users are ALWAYS True in this scenario. Additionally, IsInRole supports a check if the user is in ANY of the roles specified by delimiting the Role Names with semicolon: Administrators;Registered Users;

Format:
[FORMAT,VALUE,{ISINROLE}]

Example:
([FORMAT,”Administrators”,{ISINROLE}])

Result:
True

ISSUPERUSER


Returns a Boolean True or False value, identifying whether the current user is a super user within the environment.

Format:
[FORMAT,,{ISSUPERUSER}]

Example:
([FORMAT,,{ISSUPERUSER}])

Result:
True

Example that checks if you are a "SUPER USER":

{IIF, "[FORMAT,,{ISSUPERUSER}]=True", "I AM A SUPER USER", "I AM NOT A SUPER USER"}



ISNUMERIC


Returns a Boolean True or False value, identifying whether the value is a numeric format, or if it is a string value (non-numeric)

Format:
[FORMAT,VALUE,{ISNUMERIC}]

Example:
([FORMAT,”Not a Number”,{ISNUMERIC}])
([FORMAT,”12.435”,{ISNUMERIC}])

Result:
False
True

ISDATE


Returns a Boolean True or False value, identifying whether the value is a date format, or if it is a non date format.

Format:
[FORMAT,VALUE,{ISDATE}]

Example:
([FORMAT,”Not a Date”,{ISDATE}]) ([FORMAT,”12/4/1935”,{ISDATE}])

Result:
False True

CANEDIT


Returns a Boolean True or False value, identifying whether the current user has been granted Edit access to the specific module.

Format:
[FORMAT, ,{CANEDIT}]

Example:
([FORMAT,,{CANEDIT}])

Result:
True

EXISTS


Identifies whether the value, evaluated as a file path, points to an existing file, or a non existing file. This value is returned as a Boolean True or False.

Format:
[FORMAT,VALUE,{EXISTS}]

Example:
([FORMAT,”C:/inetpub/item4/test.txt”,{EXISTS}])
([FORMAT,”~/images/xml.gif”,{EXISTS}])

Result:
True
True

STARTSWITH


Returning a Boolean True or False value, identifies whether the value begins with the designated character value. (NEW)

Format:
[FORMAT,VALUE,{STARTSWITH:SEARCH}]

Example:
([FORMAT,”My Tab”,{STARTSWITH:My}])
([FORMAT,”My Tab”,{STARTSWITH:Our}])

Result:
True
False

 

ENDSWITH


Returning True or False, identifies if the value ends with the designated value.

Format:
[FORMAT,VALUE,{ENDSWITH:SEARCH}]

Example:
([FORMAT,”My Tab”,{ENDSWITH:ab}])
([FORMAT,”My Tab”,{ENDSWITH:abs}])

Result:
True
False

CONTAINS


Returns True or False, identifies whether the value contains the designated character value

Format:
[FORMAT,VALUE,{CONTAINS:SEARCH}]

Example:
([FORMAT,”My Tab”,{CONTAINS:ab}])
([FORMAT,”My Tab”,{CONTAINS:abs}])

Result:
True
False

INDEXOF


Returns the first index (position) of the item for which you are searching within the string

Format:
[FORMAT,VALUE,{INDEXOF:SEARCH}]

Example:
([FORMAT,”My Tab”,{INDEXOF:ab}])
([FORMAT,”My Tab”,{INDEXOF:abs}])

Result:
4
-1

LASTINDEXOF


Returns the last index (position) of the item for which you are searching within the string

Format:
[FORMAT,VALUE,{INDEXOF:SEARCH}]

Example:
([FORMAT,”My Tab Tabs”,{LASTINDEXOF:ab}])
([FORMAT,”My Tab Tabs”,{LASTINDEXOF:abs}])

Result:
8
8

Advanced Tab and Custom Look-ups


TABID


Replaces the provided Tab Name value with the associated TabID

Format:
[FORMAT,TABNAME,{TABID}]

Example:
[FORMAT,My Tab,{TABID}]

Result:
318

TABID:COLUMN


Replaces the provided value with the TabID based on a lookup on the provided Column name.

The Column provided within the syntax identifies which column is used as the lookup or search field within the Tabs table for the designated TabId. The result is always the First occurring value within the designated lookup. (NEW)

Format:
[FORMAT,VALUE,{TABID:COLUMN }]

Example:
[FORMAT,My Tab,{TABID:Title}]

Result:
318

TABNAME


Replaces the provided value with the TabName of the tab, given the specified TabId value.

Format:
[FORMAT,TABID,{TABNAME}]

Example:
[FORMAT,318,{TABNAME}]

Result:
My Tab

 

TABTITLE


Replaces the provided value with the Title of the tab, given the specified TabId value.

Format:
[FORMAT,TABID,{TABTITLE}]

Example:
[FORMAT,318,{TABTITLE}]

Result:
My Tab

TABDESCRIPTION


Replaces the provided value with the Description of the tab, given the specified TabId value.

Format:
[FORMAT,TABID,{TABDESCRIPTION}]

Example:
[FORMAT,318,{TABDESCRIPTION}]

Result:
My Tab – used for locating all my modules

SQLFIND


Provides a rapid, integrated, and simple look-up ability against any of the provided tables within the database with a specified value contained in a specific column, and returns the value of the identified return column.

Look up any value within any table and return the first result identified quickly and easily.

Format:
[FORMAT,VALUE,{SQLFIND: TABLENAME, SEARCHCOLUMN, RESULTCOLUMN }]

Example:
[FORMAT,info@bi4ce.com,{SQLFIND:employee,email_address,employee_id}]

[FORMAT,Home,{SQLFIND:Tabs,Title,TabId}]

[FORMAT,Maryland,{SQLFIND:UserProfile,Value,UserID}]

File/Path Formatting



FILE.VERSION


Format:

[FORMAT,PATH,{FILE.VERSION}]

FILE.VERSION.MAJOR


Format:

[FORMAT,PATH,{FILE.VERSION.MAJOR}]

FILE.VERSION.MINOR


Format:

[FORMAT,PATH,{FILE.VERSION.MINOR}]

FILE.VERSION.BUILD


Format:

[FORMAT,PATH,{FILE.VERSION.BUILD}]

FILE.VERSION.REVISION


Format:

[FORMAT,PATH,{FILE.VERSION.REVISION}]

FILE.VERSION.PRODUCT


Format:

[FORMAT,PATH,{FILE.VERSION.PRODUCT}]

FILE.VERSION.PRODUCT.MAJOR


Format:

[FORMAT,PATH,{FILE.VERSION.PRODUCT.MAJOR}]

FILE.VERSION.PRODUCT.MINOR


Format:

[FORMAT,PATH,{FILE.VERSION.PRODUCT.MINOR}]

FILE.VERSION.PRODUCT.BUILD


Format:

[FORMAT,PATH,{FILE.VERSION.PRODUCT.BUILD}]

FILE.VERSION.PRODUCT.REVISION


Format:

[FORMAT,PATH,{FILE.VERSION.PRODUCT.REVISION}]

FILE.VERSION.NAME


Format:

[FORMAT,PATH,{FILE.VERSION.NAME}]

FILE.VERSION.COMMENTS


Format:

[FORMAT,PATH,{FILE.VERSION.COMMENTS}]

FILE.VERSION.COMPANY


Format:

[FORMAT,PATH,{FILE.VERSION.COMPANY}]

FILE.IMAGE


Returns True/False identifying whether the file is an Image.
Format:

[FORMAT,PATH,{FILE.IMAGE}]

FILE.IMAGE.WIDTH


Returns the width of the image in pixels
Format:

[FORMAT,PATH,{FILE.IMAGE.WIDTH}]

FILE.IMAGE.HEIGHT


Returns the height of the image in pixels
Format:

[FORMAT,PATH,{FILE.IMAGE.HEIGHT}]

FILE.IMAGE.RAWFORMAT


Format:

[FORMAT,PATH,{FILE.IMAGE.RAWFORMAT}]

FILE.IMAGE.HORIZONTALRESOLUTION


Format:

[FORMAT,PATH,{FILE.IMAGE.HORIZONTALRESOLUTION}]

FILE.IMAGE.VERTICALRESOLUTION


Format:

[FORMAT,PATH,{FILE.IMAGE.VERTICALRESOLUTION}]

FILE.IMAGE.DIMENSIONS


Returns Width by Height as in 150x225
Format:

[FORMAT,PATH,{FILE.IMAGE.DIMENSIONS}]

FILE.EXISTS


Format:

[FORMAT,PATH,{FILE.EXISTS}]

FILE.FOLDER


Format:

[FORMAT,PATH,{FILE.FOLDER}]

FILE.PATH


Format:

[FORMAT,PATH,{FILE.PATH}]

FILE.NAME


Format:

[FORMAT,PATH,{FILE.NAME}]

FILE.NAMEONLY


Returns the Name without the extension
Format:

[FORMAT,PATH,{FILE.NAMEONLY}]

FILE.EXTENSION


Format:

[FORMAT,PATH,{FILE.EXTENSION}]

FILE


Returns the entire text equivalent content of the file
Format:

[FORMAT,PATH,{FILE}]

FILE.BYTES


Returns the entire byte array of the content in string format.

Format:

[FORMAT,PATH,{FILE.BYTES}]

FILE.LENGTH


Format:

[FORMAT,PATH,{FILE.LENGTH}]

FILE.SIZE


Format:

[FORMAT,PATH,{FILE.SIZE}]

FILE.CREATED


Format:

[FORMAT,PATH,{FILE.CREATED}]

FILE.UPDATED


Format:

[FORMAT,PATH,{FILE.UPDATED}]

FILE.ACCESSED


Format:

[FORMAT,PATH,{FILE.ACCESSED}]

Average (1 Ratings):
 
Want to help out?
 
 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seattle, WA • info@openwebstudio.com

Bookmark & Share Bookmark and Share