I would like to replace the occurrence of "a(x)"
and "b(x)"
in a list with "a(x-na)"
and "b(x-nb)"
where na
and nb
are the number of a
's and b
's respectively. x-na
should be evaluated.
I've tried
list = {"a(1)", "a(2)", "a(3)", "b(4)", "b(5)", "b(6)"}
na = Total[StringCount[list, "a"]]
nb = Total[StringCount[list, "b"]]
StringReplace[list, {"a(" ~~ n___ ~~ ")" ->
"a(" <> ToString[n - na] <> ")"}]
{"a(-3 + n)", "a(-3 + n)", "a(-3 + n)", "b(4)", "b(5)", "b(6)"}
But as you can see it is not working as intended.
Can you help me please?