Extracting sub-string from a string


#1

This can be done using the string method substr(int i, int j).

string str = "porcupine tree";
string new_str;

new_str = str.substr(10, str.len()-1);
$display("new_str = %s", new_str);

Output:
new_str = tree

From LRM 1800-2012 section 6.16.8
str.substr(i, j) returns a new string that is a substring formed by characters in position i through j of str.