Nexial Automation

Test Automation Platform for everyone!

X

$(format)

Description

This built-in function provides textual formatting of various common data type.  

Available Functions

$(format|base64decode|text)

base64 decode text.


$(format|base64encode|text)

base64 encode text.

Example
Script:
script

Output:
output


$(format|custom|text|format)

Customizable way to reformat text via the specified format.  The format parameter contains the back tick (`) not single quotes (‘) to represent each character in text, and all other characters as formatting characters. For example,

  • $(format|custom|ABC|`-`-`) would render A-B-C
  • $(format|custom|1234567890|(```) ```-````) would render (123) 456-7890
  • $(format|custom|1234567890|```-````) would render 123-4567
  • $(format|custom|1234567890|```-```-````) would render 123-456-7890
    Note that any unused characters will be omitted.

Example
Script:
script

Output:
output


$(format|dollar|text)

Render only the numeric characters within text as a dollar amount.   $(format|dollar|58.396) would render $58.40 - note the applied rounding.

Example
Script:
script

Output:
output


$(format|fileURI|text)

Render text into a fully qualified file path using the file:// URI scheme. Th assumption here is that text resolves to a valid local file or path. If not, text will be appended with the fully qualified path of the current project diretory. This function is particularly useful when it is necessary to create a URL for a local file for the purpose of hypertext-based content rendering (such as HTML or XML).

Example

  1. $(format|fileURI|C:\temp\myfile.txt) will be rendered as file:///C:/temp/myfile.txt.
  2. $(format|fileURI|\\network_drive\dir1\my documents\june 20202 reports.txt) will be rendered as file:////network_drive/dir1/my%20documents/june%202020%20reports.txt.
  3. $(format|fileURI|non_exisistent) will be rendered as file:///Users/user1/projects/MyProject/non_existent. Assuming that there is no file or directory named as non_existent and the current project directory is /Users/user1/projects/MyProject.

$(format|integer|text)

Render only the numeric characters within text, including the negative sign (if found). Supposed text is specified as 90abv2a.  Then $(format|integer|text) would render 902.

Example
Script:
script

Output:
output


$(format|left|text|length)

Render only the left-most portion of text, for the specified length.
One can consider this built-in function as a way to truncate text and retain its left-most characters, up to the specified length.

Note that if the specified text is less than the specified length, then the entire text will be rendered. If the specified length is less than 1, then this function will render an empty text instead.

Example
Script:
script

Output:
output


$(format|lower|text)

Convert text to its lowercase equivalent.

Example
Script:
script

Output:
output


$(format|mask|text|start|end|maskChar)

Mask certain part of text with maskChar. The start and end parameter specified where the masking should be applied. For example,

  • $(format|mask|5432109876|0|5|x) would render xxxxx9876
  • $(format|mask|Howdy folks!|5|11| ) would render Howdy
  • Note that character position is zero-based and if the positions specified is outside the range of the specified  text, then text will be rendered as is.

Example
Script:
script

Output:
output


$(format|number|text|format)

Render only the numeric characters within text, including the negative sign and decimal point (if found), using the specified format. Supposed text is specified as 90ab.v2a. Then 

  • $(format|number|${text}|#.##) would render 90.2 (# represents “minimum digit”)
  • $(format|number|${text}|000.00) would render 090.20 (0 represents “at least digit”)
    For more details on numeric format and how to specify them, consult  Decimal Format  or I18N Decimal Format.

Example
Script:
script

Output:
output


$(format|percent|text)

Render only the numeric characters within text as percentage.  Note that this function considers the value 1.0 as 100%. Hence $(format|percent|0.52448) would render 52.45%.

Example
Script:
script

Output:
output


$(format|phone|text)

Render text as a phone number, with support for various length.   - If text is less than 7 characters long, it will be rendered as is. - If text is 7 characters long, then it will be formatted as xxx-xxxx.   - If text is 10 characters long, then it will be formatted as (xxx)xxx-xxxx. - If text is 11 characters long, then it will be formatted as x(xxx)xxx-xxxx. - Otherwise, text will be rendered as x...x(xxx)xxx-xxxx, depending on the number of characters found.  Note that in this case, the formatting starts from right to left. - For more flexible formatting option, see $(format|custom|text|format).

Example
Script:
script

Output:
output


$(format|right|text|length)

Render only the right-most portion of text, for the specified length.
One can consider this built-in function as a way to truncate (from the left) text and retain its right-most characters, up to the specified length.

Note that if the specified text is less than the specified length, then the entire text will be rendered. If the specified length is less than 1, then this function will render an empty text instead.

Example
Script:
script

Output:
output


$(format|ssn|text)

Render text as a Social Security Number, in the format of xxx-xx-xxxx.  Note that exactly 9 characters are required for the formatting to be rendered, otherwise the text will be rendered as is.   For more flexible formatting option, see $(format|custom|text|format).

Example
Script:
script

Output:
output


$(format|strip|text|omit)

Render text without any of the characters specified through omit.  This is a useful/easy way to remove spaces, tabs, or punctuations.

Example
Script:
script

Output:
output


$(format|titlecase|text)

Convert text to title case - that is, the first letter of each word is converted to uppercase, while the rest to lowercase.

Example
Script:
script

Output:
output


$(format|upper|text)

Convert text to its UPPERCASE equivalent.

Example
Script:
script

Output:
output


$(format|urldecode|text)

Perform URL Encoding  on text so that it is more readable or usable for non-HTTP related processing.  Generally speaking, successive call to this function should have not varying result – such call is likely  idempotent.

$(format|urlencode|text)

Perform URL Encoding  on text so that it may be suitable as part of an URL (or URL query). Note that Nexial does not check to if text  might have already being encoded.  Hence successive calls to this function might result in undesired effect.

Example
Script:
script

Output:
output


See Also