I want to $display
strings in a column like in a fixed-width table.
However, I don't know what the maximum column width of my strings is
ahead of time.
Lets say I have an array of SystemVerilog strings (names
).
When I $display
them, I guess at a width for the column (10),
but my guess is too small:
module tb;
string names [5];
initial begin
names = '{
"ALU" ,
"COMPARATOR_3" ,
"MEMORY" ,
"FLOP" ,
"ram_macro_with_a_long_name"
};
// Display all elements of the array
foreach (names[i]) begin
$display("| %10s |", names[i]);
end
end
endmodule
This is the output:
| ALU |
| COMPARATOR_3 |
| MEMORY |
| FLOP |
| ram_macro_with_a_long_name |
This is the output I want:
| ALU |
| COMPARATOR |
| MEMORY |
| FLOP |
| ram_macro_with_a_long_name |
I could guess a really big number (like 100), but it might be a lot bigger
than I need.
How can I automatically scale the width of the $display
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…