# Append subscript to variable name [duplicate]

I'm importing equations from Word document and transforming them into input form. But subscripts look ugly.

Is is possible to programmatically append subscript to variable name?

e.g.

AppendSub[Subscript[a, 1]]=a1

-

## marked as duplicate by Jacob Akkerboom, Sjoerd C. de Vries, m_goldberg, bobthechemist, KubaApr 22 '14 at 20:59

or even Array[x, 10] /. x_[k_] :> Subscript[x, k]? – chuy Apr 22 '14 at 16:47
sorry for confusion, I clarified the question – denfromufa Apr 22 '14 at 16:55

Sure, one way is to use patterns and replacement rules (check out Symbol):

{Subscript[x, 1], Subscript[x, 2], Subscript[x, 3],
Subscript[x, 4], Subscript[x, 5], Subscript[x, 6], Subscript[x, 7],
Subscript[x, 8], Subscript[x, 9], Subscript[x, 10]} /.
Subscript[x_, k_] :> Symbol[ToString[x] <> StringReplace[ToString[k]," "->""]]
(* {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10} *)


as a function you can use:

appendSub[exp_] :=
exp /. Subscript[x_, k_] :> Symbol[ToString[x] <> StringReplace[ToString[k]," "->""]]

appendSub[{Subscript[x, 1], Subscript[x, 2], Subscript[x,
3], Subscript[x, 4], Subscript[x, 5], Subscript[x, 6], Subscript[x,
7], Subscript[x, 8], Subscript[x, 9], Subscript[x, 10]}]
(* {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10} *)

-
StringReplace[ToString[k]," "->""] helps with subscripts that have spaces – denfromufa Apr 22 '14 at 17:26