### Parse

Category

Annotation

Function

Extracts values from an input string.

Syntax

    value, ... = Parse(input, format);

Inputs

Name | Type | Default | Description
--- | --- | --- | ---
`input` | string | none | string to be operated on
`format` | string | "%s" | format control string

Outputs

Name | Type | Description
--- | --- | ---
`value` | value or string | value extracted from input string
`...` | value or string | additional values extracted

Functional Details

This module uses a format-control string (`format`) to extract values from a specified input string (`input`).

Note: The control string resembles a C-language scanf format string.

The "%" symbol in the control string specifies that extraction is to begin at the corresponding position in the input string. The character immediately following this symbol specifies the type of value to be extracted:

  `c`: single character
  `d`: integer
  `f`: floating point (with a fixed number of digits after the decimal point)
  `g`: general (scientific notation if appropriate)
  `s`: string.

The number of outputs is equal to the number of extractions specified in `format`.

Example

Given the statements:

    string = "temperature = 45.8  index = 4 color = red"
    format = "temperature = %f index = %d color = %s"
    output1, output2, output3 = Parse(string, format);

the three outputs of Parse will be 45.8, 4, and "red."

Given the statements:

    string = "/usr/home/data/cloudwater.dx"
    format = "%[^.].dx"
    ouput1 = Parse(string, format);

the output of Parse will be "/usr/home/data/cloudwater". This can be very useful to parse filenames and combined with format useful in changing the filename extension.

Example Visual Program

    UsingParse.net

See Also

Format

[ OpenDX Home at IBM | OpenDX.org ]