4

I have a list like

l = {2 - 3, 12 - 4, Times, aab}

I want to end up with

{"2-3", "12-4", "Times", "aab"}

I have tried

lh = Map[ToString, HoldForm[l], {2}]

Which gives the promising result

{ToString[2-3],ToString[12-4],ToString[Times],ToString[aab]}

However when I add ReleaseHold the numerical values get evaluated (then converted to strings).

ReleaseHold@lh

{"-1", "8", "Times", "aab"}

How can I achieve the fully unevaluated string form?

This question may be a duplicate. If so, I apologise.

kglr
  • 394,356
  • 18
  • 477
  • 896
geordie
  • 3,693
  • 1
  • 26
  • 33

2 Answers2

5
ToString /@ HoldForm /@ Unevaluated@{2 - 3, 12 - 4, Times, aab}

or

HoldForm /@ Unevaluated@{2 - 3, 12 - 4, Times, aab} /. x_ :> ToString @ x

both give

 (* {"2 - 3", "12 - 4", "Times", "aab"} *)
kglr
  • 394,356
  • 18
  • 477
  • 896
2

That might be the ugliest way to do it, but it works:

list = HoldForm@{2 - 3, 12 - 4, Times, aab};
string = ToString@list
listString = 
  StringSplit[StringReplace[string, {"{" -> "", "}" -> "", " " -> ""}], ","]

{"2-3", "12-4", "Times", "aab"}

Then, ToExpression /@ listString yields:

{-1, 8, Times, aab}
Öskå
  • 8,587
  • 4
  • 30
  • 49