Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Strings: SystemVerilog String Example

SystemVerilog Data Types

Runnable example from the SystemVerilog Strings tutorial (SystemVerilog String Example)

Open in IDE
testbench.sv
module tb;
  // Declare a string variable called "dialog" to store string literals
  // Initialize the variable to "Hello!"
  string   dialog = "Hello!";  

  initial begin
    // Display the string using %s string format
    $display ("%s", dialog);
  
    // Iterate through the string variable to identify individual characters and print
    foreach (dialog[i]) begin
      $display ("%s", dialog[i]);
    end
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.