We are preparing a new source of documentation for you. Work in progress!

Formatting strings in rules

From Resco's Wiki
Jump to: navigation, search

One of the available operations in Rules editor when building a function step is Format. The purpose of this operation is to convert a string or a series of strings to a custom format.

This operation functions similarly to the .NET composite formatting feature:

The (...) feature takes a list of objects and a composite format string as input. A composite format string consists of fixed text intermixed with indexed placeholders, called format items, that correspond to the objects in the list. The formatting operation yields a result string that consists of the original fixed text intermixed with the string representation of the objects in the list. (Microsoft documentation)

Arguments

The Format operation in Rules editor has two arguments (parameters). The first argument describes how the second argument should be formatted.

  • Arg1: Text = composite format string
  • Arg2: StringList = format items

The first argument is composite format string (Microsoft documentation). Essentially, it says how the result should look, with placeholders for strings from the second argument.

  • The placeholders are numbers in curly brackets that correspond to the index of a format item in argument 2.
  • The first format item has the index {0}.
  • The same format item can be used multiple times in a single composite format string.
  • Each format item can be further customized. For example, you can return only a date portion of a datetime variable {0:d}, you can apply currency formatting to a number {0:C2}, and much more.

The second argument is a StringList type of variable, a series or array of strings (or format items).

Examples

Form button that fills an email address

Add a button to your form. Add a Button Click rule that builds your email address from first name, last name, and a static suffix.

Format string list example.png

This is how it looks in the app:

Set email example.png

More composite format string examples

Argument 1 Argument 2 Result
Let's meet on {0:d} at {0:t}. DateTime field Let's meet on 4/10/2015 at 9:00 AM.
The price of {0} is {1:C2}. product name, price The price of Car Door Hanging Plate is $89.

See also