Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Working with Strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35021] Working with Strings
  • From: bghiggins at ucdavis.edu (Brian Higgins)
  • Date: Thu, 20 Jun 2002 02:13:18 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Odd Formatting Problem
  • Next by Date: RE: Solve weirdness
  • Previous by thread: Re: Odd Formatting Problem
  • Next by thread: RE: Working with Strings