String 如何在VHDL中将字符串转换为整数?
我正在将文本数据加载到VHDL测试台,我想将输入字符串转换为整数值 例如:“123”=>123String 如何在VHDL中将字符串转换为整数?,string,integer,type-conversion,vhdl,String,Integer,Type Conversion,Vhdl,我正在将文本数据加载到VHDL测试台,我想将输入字符串转换为整数值 例如:“123”=>123 有人能推荐一种在VHDL中将字符串转换为整数的“最佳”方法吗?readline和read函数应该可以实现您想要的功能 基本上: 打开你的文件 使用readline将文件中的下一行放入行缓冲区 使用read将行缓冲区解析为有用的数据 (可选)根据需要转换解析的值 代码段: library STD; use std.textio.all; ... variable File_Name :
有人能推荐一种在VHDL中将字符串转换为整数的“最佳”方法吗?readline和read函数应该可以实现您想要的功能 基本上:
代码段:
library STD;
use std.textio.all;
...
variable File_Name : string;
file my_file : text;
variable lineptr : line;
variable temp : integer;
...
file_open(my_file, File_Name, read_mode); -- open the file
readline(my_file, lineptr); -- put the next line of the file into a buffer
read(lineptr, temp); -- "parse" the line buffer to an integer
-- temp now contains the integer from the line in the file
...
为了便于参考。还可以使用
值属性将字符串转换为整数:
变量str:string:=“1234”;
变量int:整数;
...
int:=整数值(str);
根据需要,这可能比read()
过程更可取,因为它不会破坏性地改变源字符串。但是,只有当字符串是一个有效的整型文字,除空格外没有其他字符时,它才起作用
变量ln:line;
变量int:整数;
...
ln:=新字符串“(“456”);--空白将被忽略
int:=整数值(ln.all);--不消耗ln的内容
ln:=新字符串'(“789_000更多文本”);
int:=整数值(ln.all);--与read()不同,此操作将失败
先生的回答很有意思。谢谢