Hi everyone, I have a Ti-Basic related question concerning strings. I need a String to number converter, meaning the string comprises of numbers and I want it to easily convert to an appropiate number. Here is some help to understand it.

Code:
``` :"123456->Str1 :Length(Str1)->Dim(LNUM ://LNUM is a list, named NUM :For(A,1,Length(Str1 :sub(Str1,A,1->LNUM(A ://Invalid but the point... does anyone know how to convert easily? :End ```

What I did:

Code:
``` :"12345->Str1 :Length(Str1)->dim(LNUM :For(A,1,Length(Str1 :sub(Str1,A,1)->Str0 :If Str0="1 :1->B :If Str0="2 :2->B :If Str0="3 :3->B ://etc :B->LNUM(A :End ```

My way is pretty slow and not very effecient, does any one have a good optimized (fast) way? Thanks.
expr() should do the trick.
You can use the expr( command. So:

Code:
`expr("123`

Will return the number 123.
So:

Code:
``` :expr(sub(Str1,A,1))->LNUM(A ```

Thanks guys.

Code:
`expr(sub(Str1,A,1->LNUM(A`
Would be even better (saves 2 bytes). And, depending on how you're actually using it, if you can have the numbers already with commas, you wouldn't even need a loop:

Code:
```"1,2,3,4,15->Str1 expr("{"+Str1->LNUM```
merthsoft wrote:

Code:
`expr(sub(Str1,A,1->LNUM(A`
Would be even better (saves 2 bytes).[/code]

It's 3 bytes, not 2.
I removed two parens, how does that save 3 bytes?
merthsoft wrote:
I removed two parens, how does that save 3 bytes?
I think it's just Blue_Bear failing to read posts carefully, as usual. Take a look at my Graph3DP topic for more examples of that. It's definitely 2 bytes.
I believe he assumed there was a parenthesis at the end after the A.
Yes. I stand corrected.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Advertisement