I will do this programmatically in three steps.
Rewrite your string template in this manner:
"`a`;`b`;`a`;`c`;`a`;`c`" -> "`a0`;`b0`;`a1`;`c0`;`a2`;`c1`"
Rewrite associations to the form required to match the string template generated in the previous step.
Write a wrapper function that takes the rewritten string template and the rewritten association that now matches the string template and apply the data to the template.
Rewrite string template
Code
rewriteTemplate[tmpl_] := Module[{c},
c[Alternatives @@ Join[
CharacterRange["A", "Z"],
CharacterRange["a", "z"]
]] = 0;
StringReplace[
tmpl, {
"``" :> "",
"`" ~~ l : LetterCharacter ~~ "`" :> StringJoin[
"`", l, ToString[c[l]++], "`"
]
}]
]
Example
template = "`a`;`b`;`a`;`c`;`a`;`c`";
rewriteTemplate[template]
"`a0`;`b0`;`a1`;`c0`;`a2`;`c1`"
Reformat input data (association)
Code
makeInput[Rule[key_, val_]] := Module[{c = 0},
MapIndexed[
Rule[key <> ToString[c++], #] &,
val
]
]
makeInput[assoc_Association] := AssociationMap[makeInput, assoc]
Example
data = <|
"a" -> CharacterRange["a", "z"],
"b" -> CharacterRange["A", "Z"],
"c" -> ToString /@ Range[10]
|>;
makeInput[data]
<|"a0" -> "a", "a1" -> "b", "a2" -> "c", "a3" -> "d", "a4" -> "e",
"a5" -> "f", "a6" -> "g", "a7" -> "h", "a8" -> "i", "a9" -> "j",
"a10" -> "k", "a11" -> "l", "a12" -> "m", "a13" -> "n", "a14"...
Wrap it up!
Code
templateApply[template_, data_] := StringTemplate[
rewriteTemplate[template]
][makeInput@data]
Example
templateApply[template, data]
a;A;b;1;c;2