User guide
24-8
SystemVerilog Testbench Constructs
substr()
Returns a substring of the specified string. The arguments specify
the numbers of the characters in the specified string that begin and
end the substring.
string string1 = "abcdefgh";
string string2;
initial
begin
string2 = string1.substr(1,5);
$display("string2 = %s",string2);
end
The $display system task displays the following:
string2 = bcdef
String Conversion Methods
SystemVerilog has the following methods for converting strings:
atoi( ) atohex( ) atooct( ) and atobin( )
Returns the integer corresponding to either the ASCII decimal,
hexadecimal, octal, or binary representation of the string.
string string1 = "10";
reg [63:0] r1;
initial
begin
$monitor("r1 = %0d at %0t",r1,$time);
#10 r1 = string1.atoi;
#10 r1 = string1.atohex;
#10 r1 = string1.atooct;
#10 r1 = string1.atobin;