[Date Index]
[Thread Index]
[Author Index]
subscripts and strings
*To*: mathgroup at smc.vnet.net
*Subject*: [mg28298] subscripts and strings
*From*: Matt.Johnson at autolivasp.com
*Date*: Sat, 7 Apr 2001 03:44:59 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Hello everybody...
Here's something quirky...suppose I have some subscripted variables. Then,
I want to combine these into a string, such as in a chemical formula. So I
have the element names subscripted by the number of atoms, such as
water={Subscript[H,2],O}
then I want to combine the list into a string, H_2O (let the underscore
denote a subscript). This is where I run into problems. For some reason,
when ToString is mapped through the list, Mathematica interperets the subscripts as
newlines. So the question is, either how do I get the subscripted element
expression to be a string, or is there another way to combine these
altogether?
Thanks,
-matt
Here's a quick synopsis:
In[41]:=
\!\(\(list = {s\_1, s\_2, s\_3};\)\n
StringJoin[list]\)
\!\(List::"string" \(\(:\)\(\ \)\)
"String expected at position \!\(1\) in \!\({s\_1, s\_2, s\_3}\)."\)
\!\(List::"string" \(\(:\)\(\ \)\)
"String expected at position \!\(2\) in \!\({s\_1, s\_2, s\_3}\)."\)
\!\(List::"string" \(\(:\)\(\ \)\)
"String expected at position \!\(3\) in \!\({s\_1, s\_2, s\_3}\)."\)
General::"stop": "Further output of \!\(List :: \"string\"\) will be \
suppressed during this calculation."
Out[42]=
\!\(s\_1 <> s\_2 <> s\_3\)
In[43]:=
StringJoin[ToString /@ list]
Out[43]=
"s\n 1s\n 2s\n 3"
In[44]:=
% // InputForm
Out[44]//InputForm=
"s\n 1s\n 2s\n 3"
In[45]:=
\!\(\(list2 = {\*"\"\<\!\(s\_1\)\>\"", \*"\"\<\!\(s\_2\)\>\"", \
\*"\"\<\!\(s\_3\)\>\""};\)\[IndentingNewLine]
StringJoin[list2]\)
Out[46]=
\!\("\!\(s\_1\)\!\(s\_2\)\!\(s\_3\)"\)
In[47]:=
InputForm[%]
Out[47]//InputForm=
"\!\(s\_1\)\!\(s\_2\)\!\(s\_3\)"
**************************************************************************************************************************************
All Autoliv e-mails remain Company property and shall be used for
business-related purposes only. Do not forward any material contained
within this e-mail without prior, written permission from the author's
manager. Autoliv disclaims all responsibility and accepts no liability
(including negligence) for the consequences for any person acting, or
refraining from acting on this information prior to the receipt by those
persons of subsequent written confirmation.
**************************************************************************************************************************************
Prev by Date:
**Re: Serious bug in MatchQ causes crashes and incorrect results**
Next by Date:
**Re: Howto vonvert a list of functions in a list valued function**
Previous by thread:
**Improvement?**
Next by thread:
**Re: subscripts and strings**
| |