Re: Extracting the name of a variable
- To: mathgroup at smc.vnet.net
- Subject: [mg26906] Re: [mg26883] Extracting the name of a variable
- From: BobHanlon at aol.com
- Date: Fri, 26 Jan 2001 23:29:48 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
SetAttributes[nameExtract, HoldFirst]; nameExtract[z_Symbol] := StringReplace[ToString[Hold[z]], {"Hold[" \[Rule] "", "]" \[Rule] ""}]; x = 3; nameExtract[x] "x" Bob Hanlon In a message dated 2001/1/26 2:08:52 AM, may106 at psu.edu 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" >