I was wondering if there was a way to split a string on the TI-Nspire CX. What I want to do specifically is calculate the molar mass of a compound given that compound.
The issue I'm running into is figuring out how to split something like "NaCl" into "Na" and "Cl" in order to find the lookup values separately. Order is important as well, since a compound such as H2O will have the 2 associated with hydrogen, and not oxygen. I'm also not entirely sure when to tell the calculator to stop, as everything is in lowercase due to inputs to a function are forced to lowercase, so it seems like it would be very easy for the calculator to confuse "NaCl" for "N" and "Ac" and "Cl" or something similar.
Well, I just figured out how to use mid( and inString( to extract what I want from a string, but the issue is knowing how long the string I want to extract is.
I have a program that balances equations, perhaps you might be able to use a snippet of that? Or just use a periodic table app, and calculate it. But it was written for the 83/84 series
That might be useful. There's no point in using a periodic table app, because I already have my own set up and ready to go. This issue I'm having now is that for something like NaCl, using inString( and mid( will return C, N, Na, Cl, and Ac, and I'm not sure if there's a way to tell the calculator what to specifically look for beforehand, or even if the method I'm using is completely wrong.
http://tibasicdev.wikidot.com/archive:science:chemistry-and-physics
the part you will want is somewhere in there. under Chemistry\more\Eq Balancer
Input "Eq:",Str8
[[0->[E]
DelVar ADelVar B{0->EE
Str8+"+->Str8
inString(Ans,"=->C
DelVar U1->S
Repeat U=length(Str8
inString(Str8,"+",S->U
If Ans>C and S<C
C->U
sub(Str8,S,U-S->Str0
{0->A
Ans->E
DelVar NDelVar VDelVar WDelVar X0->Z
For(T,1,length(Str0
sub(Str0,T,1->Str9
If X
Then
inString("ieaouglrcnsbhdftypmkjqvmxz",Str9->Y
Z+1->Z
1-2(X>=30->|LA(Z
30Y+min(27,X->|LE(Z
End
If XY
Then
0->X
Else
inString("HCONBDAPSFGIKLMRTUVXYZWEJQ~-[e]plotcross*",Str9->X
End
If Ans
Then
If N
Then
For(theta,(W!=0)V+Znot(W),Z
N|LA(theta->|LA(theta
End
0->N
End
If W
Then
DelVar WDelVar V
End
Else
inString("0123456789",Str9
If Ans
Then
10N+Ans-1->N
Else
If N
Then
For(theta,(W!=0)V+Znot(W),Z
N|LA(theta->|LA(theta
End
0->N
End
If W
Then
DelVar VDelVar W
Else
If V
Then
Str9=")->W
Else
(Z+1)(Str9="(->V
End
End
End
End
End
If X
Then
1-2(X>=30->|LA(Z+1
min(27,X->|LE(Z+1
Else
If N
Then
For(theta,(W!=0)V+Znot(W),Z
N|LA(theta->|LA(theta
End
End
End
1-2(U>C->X
B+1->B
{max(1,A),B->dim([E]
For(theta,1,dim(|LE
If A
Then
sum(cumSum(|LEE=|LE(theta
If Ans
Then
A+1-Ans
[E](Ans,B)+X|LA(theta->[E](Ans,B
Else
A+1->A
|LE(theta->|LEE(A
{A,B->dim([E]
X|LA(theta->[E](A,B
End
Else
|LE(1->|LEE(1
X|LA(1->[E](1,B
1->A
End
End
U+1->S
End
A+1->A
max(A,B+1->X
{A,X->dim([E]
1->[E](A,1
1->[E](A,X
Matr>list(rref([E]),X,|LA
B->dim(|LA
cumSum(1+0|LA)not(not(fPart(|LA->E
SortD(|LE
sum(not(not(|LE->dim(|LE
For(theta,1,Ans
|LA(|LE(theta
If fPart(Ans
Then
{1,abs(Ans
Repeat |E~9>Ans(2
Ans(2){1,fPart(Ans(1)/Ans(2
End
|LAround(Ans(1)^^-1,0->A
End
End
Disp |LA
Code obtained through Cemetechs Source Coder.
Again, this was written for the Ti-83+/84 family. It gives the balancing numbers.
Given the input
C8H18+O2=CO2+H20
it will return:
{2 25 16 18}