Basically, I must write a formula on Google Sheets where I can substitute all the occurrences of a certain number for another one after it already appeared once.
For example, a certain string says "Draw {0} cards."
Where {0}
is a variable number that will be substituted for another string in a later stage (a value, a specific word, whatever).
I must concatenate this result with another specific string that says:
"Deal {0} damage."
So this should look like: "Draw {0} cards. Deal {0} damage."
However, the system does not comprise strings like this, so the formula must change the expression to "Draw {0} cards. Deal {1} damage."
. It means that whenever a number has already appeared on a string, its next occurrence must be replaced for the following one.
I know that I can use formulas like
=SUBSTITUTE(B27;"0";"1";2)
Where B27
is the cell where I concatenate the two previous strings.
The main problem here is that usually, I will not concatenate just two different strings. Sometimes there are more than 3 or 4 strings put together, and most times those strings have their own variables in a sequence.
For example, if I would concatenate those three different strings, the previous formula would not work properly:
"Draw {0} cards."
"Deal {0} damage to {1} players."
"Gain {0} life and discard {1} cards."
Simpling concatenating those strings would result in:
"Draw {0} cards. Deal {0} damage to {1} players. Gain {0} life and discard {1} cards."
But in order for this to work, I must get a result like:
"Draw {0} cards. Deal {1} damage to {2} players. Gain {3} life and discard {4} cards."
Can someone here can help me with a formula that could solve this problem? Is there any Google Sheets formula that can help? I mean, I'm a game designer, not a programmer, so scripts and some code solutions are a bit harder for me to work with.
Thank you very much for your attention.