#Dynamic String “Variables”

9 messages · Page 1 of 1 (latest)

magic furnace
#

I have a very dynamic settings config of sorts. It can reference other config values within strings, and even other random non-static variables.

Example of a config value using this: “abcdefg [config.othervalue]”

If config.othervalue was “text”, then this config value would become: “abcdefg text”

However, as I mentioned, some of the “variables” won’t be static. They might reference context that isn’t always accessible.

To insert these config values, I was originally planning to just use str.replaceAll, by just looping all the variables I would need to insert. However, since some stuff isn’t static, I’d have to do this on runtime. Likely every time the config value in question is used. Obviously this is a potential performance leak.

Is there any better way to insert the necessary variables? Some way to check what variables are used and only inserting those?

flint tideBOT
#

This post has been reserved for your question.

Hey @magic furnace! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

shell lily
#

do you really need to use regex for it

#

first thing i think is that string replacements would probably be better than regex replacements in this case

#

not exactly good, but better than regex

#

a single regex to find the replacement syntax, then you can just capture out the "variable" name and retrieve it from, say, a map to replace in

#

would only need a single iteration over the string (albeit a regex iteration)