Click or drag to resize

Formatting String Input Parameters

Strings used as input parameters to method and property commands can be formatted in a variety of ways. This topic explains the formatting options available for scalar parameters as well for string arrays.

Strings used as input parameters have format specifications of the following general form:

%[flags] [width] [.precision] [delimiter] [q | Q] s

Modifier

Interpretation

flags

-, 0

Controls justification and padding of the output, as follows:

  • - - left aligns the result with the given field width.

  • 0 - pads with zeros until the width is reached. If 0 and - appear together, the 0 is ignored.

width

Minimum field width of the output string.

precision

Maximum number of characters to send.

delimiter

The parameter must be an array of strings. The elements of the string array are sent to the device with the specified delimiter between each element.

The following delimiters are supported. Note that the enclosing parentheses are not required for comma-separated lists:

  • , or (,) - comma-separated list

  • (;) - semicolon-separated list

  • (:) - colon-separated list

  • (s) - space-separated list

  • (t) - tab-separated list

  • (r) - carriage return-separated list

  • (n) - linefeed-separated list

q

The string is formatted with enclosing single quotes (').

Q

The string is formatted with enclosing double quotes (").

Examples: Input String Parameter

Parameter Tag

Data Sent to Device

{Name:%15s}

\s\s\s\sHello World

Minimum width is 15. Pad to the left.

{Name:%-15s}

Hello World\s\s\s\s

Left justify. Pad to the right.

{Name:%.5s}

Hello

Precision specifies maximum length.

{Name:%qs}

'Hello World'

Enclose in single quotes.

{Name:%15qs}

\s\s\s\s'Hello World'

Padding is applied outside of the quotes.

{Name:%-15Qs}

"Hello World\s\s\s\s"

Left justify. Enclose in double quotes.

{NamesArray:%,5qs}

'\s\sone','\s\stwo','three','\sfour'

Field width and quotes applied to each element.

{NamesArray:%(:)Qs}

"one":"two":"three":"four"

Colon-separated list. Each element enclosed in double quotes.

See Also

Download a complete CHM version of this documentation here.