0
SystemVerilog에서 문자열 검색 및 바꾸기는 가장 쉬운 방법은 무엇입니까? 예를 들어SystemVerilog에서 문자열 검색 및 바꾸기
, 내가 가진 :
string hdl_path = "DUT.my_red39";
가 어떻게 블루 빨간색 을 대체하는 새로운 string
만들려면 어떻게해야합니까?
SystemVerilog에서 문자열 검색 및 바꾸기는 가장 쉬운 방법은 무엇입니까? 예를 들어SystemVerilog에서 문자열 검색 및 바꾸기
, 내가 가진 :
string hdl_path = "DUT.my_red39";
가 어떻게 블루 빨간색 을 대체하는 새로운 string
만들려면 어떻게해야합니까?
최근에 생성 된 SystemVerilog를 유틸리티 라이브러리 중 하나를 사용할 수 있습니다.
cl::text::replace
가 svlib_pkg::Str::replace
방법다른 방법으로, 비교 개별 문자로 일반 SystemVerilog를 함께 할 수있다 :
function automatic string search_replace(string original, string old, string replacement);
// First find the index of the old string
int start_index = 0;
int original_index = 0;
int replace_index = 0;
bit found = 0;
while(1) begin
if (original[original_index] == old[replace_index]) begin
if (replace_index == 0) begin
start_index = original_index;
end
replace_index++;
original_index++;
if (replace_index == old.len()) begin
found = 1;
break;
end
end else if (replace_index != 0) begin
replace_index = 0;
original_index = start_index + 1;
end else begin
original_index++;
end
if (original_index == original.len()) begin
// Not found
break;
end
end
if (!found) return original;
return {
original.substr(0, start_index-1),
replacement,
original.substr(start_index+old.len(), original.len()-1)
};
endfunction