Prototype: parsestringarray(array, input, comment, split, maxentries, maxbytes)

Return type: int

Description: Parses up to maxentries values from the first maxbytes bytes in string input and populates array. Returns the dimension.

These functions mirrors the exact behavior of readstringarray(), but read data from a variable instead of a file. By making data readable from a variable, data driven policies can be kept inline.

The comment field is a multiline regular expression and will strip out unwanted patterns from the file being read, leaving unstripped characters to be split into fields. Using the empty string ("") indicates no comments.

Arguments:

  • array : Array identifier to populate, in the range [a-zA-Z0-9_$(){}\[\].:]+
  • input : A string to parse for input data, in the range "?(/.*)
  • comment : Unanchored regex matching comments, in the range .*
  • split : Unanchored regex to split data, in the range .*
  • maxentries : Maximum number of entries to read, in the range 0,99999999999
  • maxbytes : Maximum bytes to read, in the range 0,99999999999

Example:

code
bundle agent __main__
{
  vars:

      #######################################
      # Define data inline for convenience
      #######################################

      "table"
        string => "Eulers Number:2.718
A Feigenbaum constant:4.6692
Tau (2pi):6.28";

      #######################################

      "dim" int => parsestringarray(
                                     "items",
                                     "$(table)",
                                     "\s*#[^\n]*",
                                     ":",
                                     "1000",
                                     "200000"
      );

      "keys" slist => sort(getindices("items"));

  reports:
      "$(keys) - $(items[$(keys)][1])";
}

Output:

code
R: A Feigenbaum constant - 4.6692
R: Eulers Number - 2.718
R: Tau (2pi) - 6.28

History: Was introduced in version 3.1.5a1, Nova 2.1.0 (2011)

See also: parserealarray(), parseintarray(), readstringarray(), readintarray(), readrealarray()