CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 151 users online: 14 members, 93 guests and 44 bots.
Members: 16aroth6, CalebHansberry, chickendude, critor, hellninjas, HOMER-16, LuxenD, pimathbrainiac, ruler501.
Bots: VoilaBot (4), Spinn3r (1), MSN/Bing (2), Magpie Crawler (4), VoilaBot (12), Googlebot (19), MSN/Bing (2).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
Author Message
zeldaking


Power User


Joined: 31 Jul 2011
Posts: 470
Location: Utah

Posted: 25 Jun 2012 11:04:35 am    Post subject: String->Number

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.
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 25 Jun 2012 11:08:25 am    Post subject:

expr() should do the trick.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
merthsoft


File Archiver


Joined: 09 May 2010
Posts: 2735

Posted: 25 Jun 2012 11:08:39 am    Post subject:

You can use the expr( command. So:

Code:
expr("123

Will return the number 123.
_________________
Shaun
Back to top
zeldaking


Power User


Joined: 31 Jul 2011
Posts: 470
Location: Utah

Posted: 25 Jun 2012 11:12:12 am    Post subject:

So:

Code:

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

Thanks guys.
Back to top
merthsoft


File Archiver


Joined: 09 May 2010
Posts: 2735

Posted: 25 Jun 2012 11:13:13 am    Post subject:


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

_________________
Shaun
Back to top
blue_bear_94


Member


Joined: 20 Apr 2012
Posts: 162

Posted: 25 Jun 2012 12:07:31 pm    Post subject:

merthsoft wrote:

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

It's 3 bytes, not 2.
Back to top
merthsoft


File Archiver


Joined: 09 May 2010
Posts: 2735

Posted: 25 Jun 2012 12:47:05 pm    Post subject:

I removed two parens, how does that save 3 bytes?
_________________
Shaun
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55742
Location: Earth, Sol, Milky Way

Posted: 25 Jun 2012 01:03:50 pm    Post subject:

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. Wink Take a look at my Graph3DP topic for more examples of that. It's definitely 2 bytes.
_________________


Back to top
graphmastur


Power User


Joined: 27 Jul 2010
Posts: 464

Posted: 25 Jun 2012 06:39:12 pm    Post subject:

I believe he assumed there was a parenthesis at the end after the A.
Back to top
blue_bear_94


Member


Joined: 20 Apr 2012
Posts: 162

Posted: 26 Jun 2012 10:49:11 am    Post subject:

Yes. I stand corrected.
_________________
Do NOT click any links!
Back to top
Display posts from previous:   
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.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 
Jump to:  
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

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.033258 seconds.