Professional Documents
Culture Documents
Strings
Strings
The SystemVerilog string type holds variable-length strings. An individual character is of type
byte. The elements of a string of length N are numbered 0 to N-1. Memory for strings is
dynamically allocated.
Example :
module str;
string A;
string B;
string serch_str = "SystemVerilog supports search( ) method";
integer i;
initial
begin
A = "SASKEN ";
B = "TECHNOLOGIES";
// String methods
$display(" %d ",A.len() );
$display(" %s ",A.getc(5) );
$display(" %s ",A.tolower);
$display(" %s ",B.toupper);
$display(" %d ",B.compare(A) );
$display(" %d ",A.compare("test") );
$display(" %s ",A.substr(2,3) );
A = "10"
$display(" %d ",A.atoi() );
$display(" %d ",A. atohex () );
$display(" %d ",A.atooct () );
$display(" %d ",A. atobin () );
// string operators
if(A == B); // equality
i = {A,B}; // concatanaton
i = {{3{A}},B}; // Replication
end
endmodule