MathGroup Archive 2002

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

Search the Archive

Re: Working with Strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35085] Re: [mg35021] Working with Strings
  • From: Omega Consulting <omega_consulting at yahoo.com>
  • Date: Mon, 24 Jun 2002 03:21:46 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

The default format for ToString is OutputForm, which does not include 
quotes. If you use InputForm, then you'll get quotes inside the string and 
To Expression will see the elements of the list as strings, not expressions.

In[1]:= mystring = {"cis-3-hexene", "acetone"}

Out[1]= {cis-3-hexene, acetone}

In[2]:= newstring = ToString[mystring, InputForm]

Out[2]= {"cis-3-hexene", "acetone"}

In[3]:= ToExpression[newstring]===mystring

Out[3]= True

At 01:13 AM 6/20/2002, Brian Higgins wrote:
>Hi Mathgroup,
>
>In a webMathematica application I need to process string information.
>The essential problem is as follows. The user selects  chemical
>species such as
>
>species1 = "cis-3-hexene";
>species2 = "acetone";
>
>Ideally these strings need to be processed into a list by using
>AppendTo to obtain
>
>mystring = {"cis-3-hexene", "acetone"}.
>
>Then finally this list has to be converted to a string to be passed by
>the web browser for another 'session',  as follows
>
>In[13]:=ToString[mystring]
>
>Out[13]="{cis-3-hexene, acetone}"
>
>The problem is that in the new session I need to convert this string
>back to a Mathematica expression for further processing, and when I do
>this the data get corrupted:
>
>In[14]:=ToExpression[ToString[mystring]]
>
>Out[14]={-3 + cis - hexene, acetone}
>
>I have figured a way around this problem but it is in my opinion
>obtuse and I am looking for a more direct way to handle my problem.
>Any thoughts?
>
>Here is the way I handle it now.
>
>Instead of using AppendTo I create the string for passing to the
>browser as follows
>
>ClearAttributes[Plus, Orderless]
>specieslist = ToString[species1 + species2]
>
>(Note the order is important)
>
>In the new session this string is processed with the following
>function
>
>stringList[mylist_] :=
>   Module[{aa},
>     aa = DeleteCases[Characters[mylist], x_ /; x == " ",
>           Infinity] //. {x1___, "+", x2___} :> {{x1}, {x2}};
>     Cases[aa, {x__String} :> StringJoin[x], Infinity]]
>
>In[16]:=stringList[specieslist]
>
>Out[16]={"cis-3-hexene", "acetone"}
>
>
>Thanks in advance for any help you can offer,
>
>
>Brian

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.
http://www.wz.com/internet/Mathematica.html



  • Prev by Date: Re: Re: Solve weirdness again
  • Next by Date: Re: friendly challenge 3
  • Previous by thread: RE: Working with Strings
  • Next by thread: can I make an assumption in Mathematica ??