• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. How can a concatenated string be transformed into a variable...

Stats

  • Replies 6
  • Subscribers 151
  • Views 78
  • Members are here 0

How can a concatenated string be transformed into a variable name?

SZ20260803361
SZ20260803361 23 hours ago

I want to set a variable name that can change over time. For example:
item=""
lists=setof(i parseString(getCurrentTime() "") i!) =" "&&i! =":")
foreach(elem lists

item=strcat(item elem)
)
I received the item with the code "Aug201706212026".
I want to replace the "item" in the variable name "a_item" with "Aug201706212026", so that the final variable name becomes "a_Aug201706212026". How can I do this? I tried using `setq(stringToSymbol(strcat("a_" item)) 5)`, but this caused an error. How should I proceed?

  • Sign in to reply
  • Cancel

Top Replies

  • Andrew Beckett
    Andrew Beckett 20 hours ago +1
    This is almost certainly not what you want to do, because creating different variable names on the fly usually means you should be creating a different data structure - e.g. a hash table indexed by the…
Parents
  • Andrew Beckett
    Andrew Beckett 20 hours ago

    This is almost certainly not what you want to do, because creating different variable names on the fly usually means you should be creating a different data structure - e.g. a hash table indexed by the date rather than a unique variable name. However, if you really want to do this (the wrong way in my opinion), then taking your code:

    item=""
    lists=setof(i parseString(getCurrentTime() "") i!=" " && i!=":")
    foreach(elem lists
        item=strcat(item elem)
    )

    (I assume you used some kind of optical character recognition because it had some spurious parentheses) then you could do:

    set(concat("a_" item) 5)

    you can retrieve it with:

    symeval(concat("a_" item))

    A cleaner (more efficient in terms of creating garbage that needs collecting) way of building the variable name would be to do:

    cleanup=pcreCompile("[ :]")
    varName=concat("a_" pcreReplace(cleanup getCurrentTime() "" 0))

    However, if you creating a number of these, I'd use a hash table (using makeTable) as I mentioned before.

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • SZ20260803361
    SZ20260803361 5 hours ago in reply to Andrew Beckett

    Dear Mr. Beckett,

    Thank you very much for your prompt, professional and informative replies. I have tried both of your proposed methods, and both work as I expected. I will test the hash‑table approach you suggested later. I will elaborate on why I require dynamic variable names based on a small ongoing project I am developing, and seek your advice on the issues I have encountered during development.

    Best regards,
    Steve

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • SZ20260803361
    SZ20260803361 5 hours ago in reply to Andrew Beckett

    Dear Mr. Beckett,

    Thank you very much for your prompt, professional and informative replies. I have tried both of your proposed methods, and both work as I expected. I will test the hash‑table approach you suggested later. I will elaborate on why I require dynamic variable names based on a small ongoing project I am developing, and seek your advice on the issues I have encountered during development.

    Best regards,
    Steve

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2026 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information