I have a global rule as follow:
transformRules =
{a1 -> Subscript[Style["a", Italic], 1],
b1 -> Subscript[Style["b", Italic], 1],
c1 -> Subscript[Style["c", Italic], 1],
d1 -> Subscript[Style["d", Italic], 1],
e1 -> Subscript[Style["e", Italic], 1],
f1 -> Subscript[Style["f", Italic], 1],
a2 -> Subscript[Style["a", Italic], 2],
b2 -> Subscript[Style["b", Italic], 2],
c2 -> Subscript[Style["c", Italic], 2],
d2 -> Subscript[Style["d", Italic], 2],
e2 -> Subscript[Style["e", Italic], 2],
f2 -> Subscript[Style["f", Italic], 2],
A1 -> Subscript[Style["A", Italic], 1],
B1 -> Subscript[Style["B", Italic], 1],
C1 -> Subscript[Style["C", Italic], 1],
D1 -> Subscript[Style["D", Italic], 1],
E1 -> Subscript[Style["E", Italic], 1],
F1 -> Subscript[Style["F", Italic], 1],
A2 -> Subscript[Style["A", Italic], 2],
B2 -> Subscript[Style["B", Italic], 2],
C2 -> Subscript[Style["C", Italic], 2],
D2 -> Subscript[Style["D", Italic], 2],
E2 -> Subscript[Style["E", Italic], 2],
F2 -> Subscript[Style["F", Italic], 2]};
It is tedious to write them one-by-one. So I write a function to transform then automatically.
Thanks for Kuba's hints
transform=
# -> Subscript[Style[#1, Italic], #2] & @@ StringSplit[ToString[#], ""] &
transformRules =
Function[
{symbol},
symbol ->
Subscript[Style[#1, Italic], #2] & @@ StringSplit[ToString[symbol], ""]]
transformRules =
transform /@
{a1, b1, c1, d1, f1, a2, b2, c2, d2, e2, f2, A1, B1, C1, D1, E1, F1}
However, my auxiliary function transform
cannot apply the following cases:
transform[AA1]
transform[AB12]
And I also know that the main problem is StringSplit[ToString[#], ""]
Question
This my first time to use the string function, and I search teh DOC about StringSplit
. However, I cannot solve it.
- How to split the string acoording the number?
For example,
A1-> {"A","1"}, AB1-> {"AB","1"}, AB12-> {"AB","12"},ABC12-> {"ABC","12"}
_Symbol->Subscript[_String, _Integer]
or_Symbol->Subscript[_String, _String]
$\endgroup$