字符串去除行尾空格 函数
// 去除字符串末尾的换行符和空格符
function string remove_trailing_whitespace(string str);int len = str.len();int last_valid_index = -1;// 空字符串直接返回if (len == 0) return "";// 从后向前找到第一个非空白字符的位置for (int i = len - 1; i >= 0; i--) beginbyte ch = str[i];// 如果不是空格、制表符、换行符、回车符if (ch != " " && ch != "\t" && ch != "\n" && ch != "\r") beginlast_valid_index = i;break;endend// 如果全是空白字符,返回空字符串if (last_valid_index == -1) return "";// 返回截取后的字符串return str.substr(0, last_valid_index);
endfunction
**如果要将function 定义成pub function 可以包含在pkg中 import导入UVM各组件调用,但是function 要定义成automatic function 否则调用会报错**