Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting the name of a variable

  • To: mathgroup at
  • Subject: [mg26906] Re: [mg26883] Extracting the name of a variable
  • From: BobHanlon at
  • Date: Fri, 26 Jan 2001 23:29:48 -0500 (EST)
  • Sender: owner-wri-mathgroup at

SetAttributes[nameExtract, HoldFirst];

nameExtract[z_Symbol] := 
    StringReplace[ToString[Hold[z]], {"Hold[" \[Rule] "", "]" \[Rule] ""}];

x = 3;



Bob Hanlon

In a message dated 2001/1/26 2:08:52 AM, may106 at writes:

>I'd like to make a function that extracts the name of a variable and
>makes a string. So the function would do:
>In:  z = 4
>In: nameExtract[z]
>Out: "z"
>It appears to not be so simple, since once you assign z a value, the
>function SymbolName[z] returns an error. what's the trick?
>I want to do this so I can make a function takes z as an argument, and
>generates a name:value pair  "z=4"

  • Prev by Date: RE: Q: lefthand/right hand side of equation
  • Next by Date: Re: Napoleon
  • Previous by thread: Re:Extracting the name of a variable
  • Next by thread: RE: Extracting the name of a variable