RE: Working with Strings
- To: mathgroup at smc.vnet.net
- Subject: [mg35059] RE: [mg35021] Working with Strings
- From: "DrBob" <majort at cox-internet.com>
- Date: Thu, 20 Jun 2002 23:55:10 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Here's an option (within a session): mystring = {"cis-3-hexene", "acetone"}; Off[DeleteFile::"nffil"] DeleteFile["tmp"] On[DeleteFile::"nffil"] Save["tmp", mystring]; Clear[mystring] Get["tmp"]; mystring DumpSave can replace Save, and may be more efficient. With Save, you can look at the contents of "tmp" to see what's going on. You'll see that this method doesn't require you to know what variables you're reading with Get. You could communicate between sessions by writing to an external file like that, but I suspect you're already using a stream of some sort. I've never seen that done between sessions, so I can't guess the easiest way to modify what you're doing. In general, you definitely need to read the data a different way and possibly to write it a different way. Bobby Treat -----Original Message----- From: Brian Higgins [mailto:bghiggins at ucdavis.edu] To: mathgroup at smc.vnet.net Subject: [mg35059] [mg35021] Working with Strings 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