Home / Learn Verilog / Strings in SystemVerilog

Strings in SystemVerilog

A real string type.

Bottom lineA real string type.

Breaking it down

string methodss.len()s.toupper() / tolower()s.substr(i, j){s1, s2} concatenation
string methods

Definition

The string type has len(), toupper(), substr(), compare() and more.

Why you need this

Logging and file handling in testbenches.

How it works

Testbench only.

Where you'll see this

  • Everyday RTL design
  • FPGA and ASIC projects
  • Testbenches and debugging

Try it

ASCII bytes of a stringVerilog: edit and run

A string is just bytes in plain Verilog.

SystemVerilog string
string s = "Hello";\ninitial begin\n  $display("%0d", s.len());        // 5\n  $display("%s", s.toupper());     // HELLO\n  $display("%s", s.substr(1, 3));  // ell\nend
Careful:This simulator runs the core of SystemVerilog (logic, always_ff, always_comb, enum, typedef, int, loops with int, break/continue, inside, immediate assert). Features shown only in the grey code box need a full simulator (Icarus -g2012, Verilator, Questa, VCS, Xcelium).

Test what you just read

1. s.len() returns...