According to the package named Standard in VHDL, the string is actually declared as array of character type where the character type itself is also defined within the package.

Provided that I am filling in a string with data which shall then be written to a file and the size of the string cannot be known in advance, how do I declare a "variable length string"?

I am aware that the Line type exists from textio. However, I don't know if it is possible to actually concatenate different line variables and then write them to a file. If this is possible then my problem can be solved.


A string is an array of characters with a fixed range. As for any other array type in VHDL, strings can be concatenated using the & operator resulting in a new string (with a new size).
For variable length strings you could use an access string type which can point to a variable length string. Similar questions were asked before.
If you need to handle arrays of strings, the easiest way is probably to define an array of fixed size strings along with a couple of trim() and pad() functions.

| improve this answer | |
  • \$\begingroup\$ If I am to concatenate a string e.g str_a = str_a & temp_str, I am sure that will not work since str_a has a fixed size to begin with right? Anyway, I have worked out a solution using the line variable which you have mentioned. \$\endgroup\$ – quantum231 Feb 18 '16 at 23:55
  • 2
    \$\begingroup\$ Using NUL as a fill character is not supported by all VHDL tools. Using characters greater then CHARACTER'val(127) in source code is not allowed (VHDL files are ASCII encoded not ANSI) and explicitly using CHARACTER'val(255) causes some VHDL tools to crash or to write the synthesis log window in reverse order .... Have a look at our PoC.strings package on how to implement several string functions for fixed sized strings. \$\endgroup\$ – Paebbels Feb 19 '16 at 2:53
  • \$\begingroup\$ The CWRU packages implement a C like capability for VHDL strings. See bear.ces.case.edu/VHDL/index.html \$\endgroup\$ – Jim Lewis Feb 19 '16 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.