在 VHDL 中修改字符串的最佳方法 [英] Best way to modify strings in VHDL

查看:36
本文介绍了在 VHDL 中修改字符串的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为我所做的 VHDL 设计编写测试平台,我需要将消息写入文本文件.消息格式为

I'm currently writing a test bench for a VHDL design I made and I need to write a message to a text file. The message is of the format

[instance_name];[simulation_time] 

(即 U0;700 ns)并且文件名必须是 [instance_name].log.获取实例名称和模拟时间没有问题,但写入自定义文件名一直存在问题.在模拟下,实例名称将以以下格式给出:

(i.e. U0;700 ns) and the filename must be [instance_name].log. Getting the instance name and simulation time is no problem, but writing to a custom filename has been problematic. Under simulation, the instance name will be given in the format:

"U0\ComponentX\test\" 

我想用下划线替换斜线.有没有简单的方法可以做到这一点?

and I would like to replace the slashes with underscores. Is there an easy way to do this?

推荐答案

我们的 PoC Library 有关于字符串操作/函数的大量集合.str_replace 函数"nofollow">PoC.strings 应该可以解决您的问题.还有 PoC.utils 包与字符串无关的函数,这也有助于处理字符串和文件 I/O.

Our PoC Library has quite a big collection on string operations/functions. There is a str_replace function in PoC.strings that should solve your question. There is also the PoC.utils package with non string related functions, that could also be helpful in handling strings and file I/O.

一个简单的实现:

function replace(str : STRING) return STRING
  variable Result : STRING(str'range) := str;
begin
  for i in str'range loop
    if (Result(i) = '\') then
      Result(i)  := '_';
    end if;
  loop;
  return Result;
end function;

用法:

constant original : STRING := "U0\ComponentX\test\";
constant replaced : STRING := replace(original);

这篇关于在 VHDL 中修改字符串的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆