Reading string from a file, including whitespaces while excluding delimiters

Hi.
I have the following as a reference input line:
“HEADER | DESC_part1 DESC_part2 … DESC_partN | WORD 10”

And I want to extract two elements:

  1. a concatenated version of the DESC to a single string e.g. desc_STR = “DESC_part1 DESC_part2 … DESC_partN”
  2. The decimal value after “WORD”

As long as the DESC does not include whitesapces, the following code does the work:


initial begin
      integer status;
      string status_STR;
      string desc;
      integer val;
      string val_STR;
      status = $sscanf(inputSTR,"HEADER | %s | WORD %d",desc,val);
      val_STR.itoa(addr);
      if (status == 2) begin
        $display("SUCCESS");
        $display({"desc is : ", desc});
        $display({"addr is : ", addr_STR});
      end
      else begin
        $display("FAILURE");
      end
    end

When the DESC consists of multiple whitespace separated strings:
status = 1
desc = DESC_part1
val = ?

When I try to exclude characters in the format specifier i.e. “[^|]”, I get the following error:
**
An invalid input format specifier ‘%{’ is passed as part of the second argument
**

What am I missing? Is character excluding forbidden in verilog?

Thanks.
Itay.

In reply to itay yehekzel karo:

SystemVerilog only supports a limited subset of string formatting capabilities from C. Verilog was introduced before C/C++ was in the mainstream and has features that diverge from it. You can use the DPI and wrap calls to C’s sccanf if you want the full functionality.