SystemVerilog String Concatenation

Michael Aug 03, 2026
some calculations are shown in the text
some calculations are shown in the text

SystemVerilog, an extension of Verilog, offers powerful features like user-defined types, classes, and advanced data types, enabling complex system-on-chip (SoC) designs. One of its key strengths is string manipulation, a staple in high-level languages, now available in hardware description languages (HDLs). String concatenation in SystemVerilog is a fundamental operation, allowing designers to create dynamic strings and labels.

some calculations are shown in the text
some calculations are shown in the text

In this comprehensive guide, we will explore the intricacies of string concatenation in SystemVerilog. We will delve into the basics, discuss concatenation operators, explore string types, and provide practical examples to illustrate these concepts. By the end of this article, you will have a solid understanding of string concatenation in SystemVerilog and be able to apply this knowledge in your designs.

C string concatenation
C string concatenation

Understanding SystemVerilog Strings

Before we dive into string concatenation, let's first understand the different string types in SystemVerilog. SystemVerilog supports both static and dynamic string types. Static strings are compile-time constants, while dynamic strings can grow and shrink at runtime.

Strings & String Methods 💻
Strings & String Methods 💻

SystemVerilog utilizes the `string` data type to represent strings. It supports both null-terminated and fixed-length strings. The length of a string is defined by its number of characters, including the null character if the string is null-terminated.

Static Strings

some type of text that appears to be in english
some type of text that appears to be in english

Static strings are defined within double quotes (" "). The length of a static string is determined during compilation. For instance:

string static tekst = "Welcome to SystemVerilog";

Dynamic Strings

Dynamic strings are declared with the `string` keyword, preceded by a single quote (' ). The length of a dynamic string is not determined during compilation and can change at runtime. For example:

four hands reaching out towards each other with red lines in between them and on top of black and white photograph
four hands reaching out towards each other with red lines in between them and on top of black and white photograph

string dynamic_text = '';

String Concatenation Operators

SystemVerilog provides two operators for string concatenation: the concatenation operator `||` and the concatenation assignment operator `+=`.

The `||` operator concatenates two or more strings, returning a new string. For instance:

Tangled Thread Works - Clare Nicholls
Tangled Thread Works - Clare Nicholls

string result = "Hello" || "World";

In this case, `result` will hold the value `"HelloWorld"`.

The `+=` operator concatenates a string to the right-hand side (RHS) value and assigns the result to the left-hand side (LHS) value. For example:

String concatenation using StringBuilder class
String concatenation using StringBuilder class
a wall with many lines on it that are connected to different things in the background
a wall with many lines on it that are connected to different things in the background
C# String
C# String
mims industries
mims industries
Cosmology And String Theory (Fundamental Theories Of Physics, 197)
Cosmology And String Theory (Fundamental Theories Of Physics, 197)
three hands holding pink string in the shape of a star
three hands holding pink string in the shape of a star
La théorie des Cordes
La théorie des Cordes
an abstract art work with white lines and rock in the middle, against a black background
an abstract art work with white lines and rock in the middle, against a black background
Complete Computer Science & Cybersecurity Infographics Bundle
Complete Computer Science & Cybersecurity Infographics Bundle
STRING THEORY by ManaDawn Tabletop Games
STRING THEORY by ManaDawn Tabletop Games

string result = "Hello";
result += "World";

Here, `result` will also hold the value `"HelloWorld"`.

String Concatenation with Non-String Types

SystemVerilog also allows concatenating strings with other data types using the `||` operator. Numeric values are automatically converted to strings, while scalars are converted to their textual representations. For instance:

string result = "The answer is " || 42 || "!";

In this example, `result` will be `"The answer is 42!"`.

Escaping Special Characters

Sometimes, you may need to include special characters like double quotes ("), single quotes ('), or backslashes (\\\) within a string. To do this, prefix the special character with a backslash (\\). For example:

string quote_example = "He said, \\"I do\\";

Here, `quote_example` will contain the string `"He said, "I do"`.

Practical Examples of String Concatenation

Now that we have explored the basics of string concatenation let's look at some practical examples.

String Manipulation for Debug Purposes

String concatenation is frequently used inSystemVerilog for debug purposes. Designers can create dynamic messages to aid in debugging complex SoC designs. For instance:

initial begin
  $display("Module %s has finished execution, Elapsed time %dns", $unit_name(), $time);
end

Generating Labels at Runtime

String concatenation can also be used to create dynamic labels at runtime. This can be useful when designing testbenches or when the number of signals to monitor is high. For example:

initial begin
  always @(posedge clk) begin
    logic value = reg_val & ~neg_reg;
    $display("Reg Val: %b, Neg Reg: %b, Logic Value: %b", reg_val, ~neg_reg, value);
  end
end

In this example, the `$display` statement generates a dynamic label based on the sampled values of `reg_val`, `~neg_reg`, and `value`.

String concatenation in SystemVerilog is a powerful tool, allowing designers to create dynamic strings and labels. By understanding the different string types and concatenation operators, you can effectively utilize this feature in your designs. Whether you're creating dynamic messages for debugging or generating runtime labels, string concatenation provides the flexibility required for complex SoC designs.