You are on page 1of 2

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 Pattren Match


i = serch_str.search("supports");
$display(" %d \n", i);
i = serch_str.match("supports");
$display(" %d \n", i);
i = serch_str.prematch();
$display(" %s \n", i);
i = serch_str.postmatch();
$display("%s \n", i);

// string operators
if(A == B); // equality

if(A != B); // inequality


if(A < B); // comapison
if(A <= B); // comapison
if(A> B); // comapison
if(A>=B); // comapison

i = {A,B}; // concatanaton
i = {{3{A}},B}; // Replication

for(int i=0; i<5;i++) // indexing


$write("%s",A[i])

end
endmodule

You might also like