Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: lookitsan00b on December 14, 2010, 11:45:12 pm

Title: Fun with strings!
Post by: lookitsan00b on December 14, 2010, 11:45:12 pm
Y DUZ DIS GIB M3 A 3R0R? :banghead:

Code: [Select]
:If sub(Str1,1,1)="""
:Then
...
:End

Spoiler For edit:
I DO want all three quotes there. It worked fine with Str0, and that's what [RCL][VARS][7][0] spits out.
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 14, 2010, 11:52:14 pm
Sadly TI-BASIC doesn't support that. It gives an error because the parser is designed to think that the second quote ends the string, so it sees the third one as a Syntax error. The only way to display quotes is to use Input function and type a quote, stored in a string variable, and have the person using your program send that string to his calc along with your program. Otherwise, if you use Text( you just have to use two ' characters.
Title: Re: Fun with strings!
Post by: lookitsan00b on December 14, 2010, 11:56:15 pm
 :'(

is there any other way to check if the contents of a string would evaluate to a string (preferably not involving errors)?
Title: Re: Fun with strings!
Post by: meishe91 on December 15, 2010, 12:05:17 am
What do you mean? I don't understand what you're asking for really.

But ya, as DJ said you can't have a quotation mark inside of a string unless you do a lot of tricks.
Title: Re: Fun with strings!
Post by: AngelFish on December 15, 2010, 12:06:01 am
Or use Assembly  ;)

*DJ, Not saying that anyone needs to learn ASM.
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 15, 2010, 12:08:44 am
Yeah I know. Sadly I think ASM (or Axe?) is the only way to force the storage of a string quote character in a string.

I wonder about STO...
Title: Re: Fun with strings!
Post by: lookitsan00b on December 15, 2010, 12:12:37 am
basically, I'm doing:

Code: [Select]
:input Str1,""
:Str1->u           //thats the graphing variable

Ok, so now I need to know what data type u is. I have tests for everything but strings.

EDIT: Na. I wanna save all my assembly routines for blocking ON, APPS, and [2nd][Quit] :P
Title: Re: Fun with strings!
Post by: meishe91 on December 15, 2010, 12:17:24 am
So you want to test a string if it is a string, number, list, matrix, or something else?
Title: Re: Fun with strings!
Post by: AngelFish on December 15, 2010, 12:19:04 am
U is a numeric variable. It can hold any numeric value... but not much else. You can use the ANS variable if you want, though. It will hold any normal type variable you care to use. If you want to test for variable type without errors, you're most likely going to be forced into using Assembly, which makes it fairly trivial.
Title: Re: Fun with strings!
Post by: JosJuice on December 15, 2010, 09:29:54 am
Yeah I know. Sadly I think ASM (or Axe?) is the only way to force the storage of a string quote character in a string.

I wonder about STO...
I believe it's possible to store a " inside a string if it's typed into the homescreen, recalled to the Y= editor, and then stored in a string from either the homescreen or a TI-BASIC program.
Title: Re: Fun with strings!
Post by: TIfanx1999 on December 15, 2010, 09:41:36 am
I think it's mentioned on TIBD somewhere...
here: http://tibasicdev.wikidot.com/strings (http://tibasicdev.wikidot.com/strings)
It's listed under the "Advanced" heading. =)
Title: Re: Fun with strings!
Post by: lookitsan00b on December 15, 2010, 09:53:00 am
I know its possible to do that, it's also really easy to just do :Input Str1 and type in a double quote... but I don't want to have to include the string with the program.

And yes, u IS a graphing variable. [2nd][7]. try it.

I'm storing the string to that, then getting the answer right back from it. All its doing for me is converting the string from Input into the corresponding data type.

So you want to test a string if it is a string, number, list, matrix, or something else?

Exactly.
Title: Re: Fun with strings!
Post by: Happybobjr on December 15, 2010, 10:27:13 am
:'(

is there any other way to check if the contents of a string would evaluate to a string (preferably not involving errors)?

ya, you could use '' instea of "   ....
Title: Re: Fun with strings!
Post by: Deep Toaster on December 15, 2010, 10:48:10 am
He wants to check if it contains the " token, though, to see if Str1 contains a string within the string, so '' wouldn't work.

I don't think it's possible, except for that Y= trick, unfortunately.
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 15, 2010, 02:55:50 pm
What Deep Thought said. You'll have to use some Axe or assembly otherwise, I'm afraid. The TI-OS has some weird limitations sometimes. Another example is how the Sto char cannot be used inside strings at all, even through Y= and Input...
Title: Re: Fun with strings!
Post by: Deep Toaster on December 15, 2010, 03:58:39 pm
You can put it in a string through Y=. If you type it on the homescreen and RCL it to the Y= prompt, you can do whatever you want with it.
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 15, 2010, 04:06:18 pm
It doesn't work. When I type the STO char in Y= it does nothing. It won't let me type it ???
Title: Re: Fun with strings!
Post by: lookitsan00b on December 15, 2010, 04:35:26 pm
It doesn't work. When I type the STO char in Y= it does nothing. It won't let me type it ???

1: type "-> on the homescreen, press enter, then quit (when it gives an error)
2: go to Y= and push [2nd][Enter].

that should do it!

but c'mon guys there has to be another way... like:

Code: [Select]
:If inString("every_single_token_except_"_and_->",sub(Str1,1,1))
:Else
...
:End

I could use XTRACHAR for that... I keep it on-calc at all times :P

But it'll run horribly slow.
Title: Re: Fun with strings!
Post by: Deep Toaster on December 15, 2010, 04:50:50 pm
Nope, unfortunately there's no way at all to check unless you (1) have an ASM sub or (2) already have the chars stored in a string, like with the Y= trick.
Title: Re: Fun with strings!
Post by: lookitsan00b on December 15, 2010, 05:31:11 pm
are you saying there's a length limit with inString(?

I cant do inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz {[max(min(int(fPart(...etc...GarbageCollect",sub(Str1,1,1)) ???

because, then, by process of elimination, it has to be " or -> (or be something like sub(, which'll return a string anyways ) >:D

as I said, that'd run really slow :-\
Title: Re: Fun with strings!
Post by: Builderboy on December 15, 2010, 05:32:18 pm
It would worlk, but there are over 9000 different possible tokens you can have on the calculator, so it would be incredibly inefficient, slow, and large.  Maybe if you tell us exactly what you want to accomplish we can see if there is a better way to accomplish what you are trying to do?
Title: Re: Fun with strings!
Post by: FinaleTI on December 15, 2010, 05:37:37 pm
This (http://www.unitedti.org/forum/index.php?showtopic=9191&view=findpost&p=139646) might be a start.
You can check if Ans is a number or a String with these methods, but I'm not sure how helpful it is for what you're trying to do.
Title: Re: Fun with strings!
Post by: meishe91 on December 15, 2010, 06:26:55 pm
I was looking for that! Thanks, Finale. I thought it was on TIBD though but oh well, at least it was found.

From what I understand he is trying to get the user to input something, a list, a string, a number, a matrix, or whatever, and then he stores it into u (for a reason I don't understand because it acts like a string except it outputs a number...) and then runs u through a series of tests to test what it is (a list, matrix, string, number, etc.).
Title: Re: Fun with strings!
Post by: lookitsan00b on December 15, 2010, 06:44:23 pm
lol that doesn't work with any input.  What about matrices?  >:D
Title: Re: Fun with strings!
Post by: meishe91 on December 15, 2010, 09:18:26 pm
Are you talking about the link that Finale gave? You could do checks for all of them but string and number and if it gets that far then you do that check to decide which it is.
Title: Re: Fun with strings!
Post by: lookitsan00b on December 15, 2010, 09:41:14 pm
Are you talking about the link that Finale gave? You could do checks for all of them but string and number and if it gets that far then you do that check to decide which it is.

lol I know I just wanted to be evil :P
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 16, 2010, 04:44:55 am
It doesn't work. When I type the STO char in Y= it does nothing. It won't let me type it ???

1: type "-> on the homescreen, press enter, then quit (when it gives an error)
2: go to Y= and push [2nd][Enter].

that should do it!

but c'mon guys there has to be another way... like:

Code: [Select]
:If inString("every_single_token_except_"_and_->",sub(Str1,1,1))
:Else
...
:End

I could use XTRACHAR for that... I keep it on-calc at all times :P

But it'll run horribly slow.
Ah that works! Too bad I can't display it with Output or something...
Title: Re: Fun with strings!
Post by: lookitsan00b on December 16, 2010, 09:15:05 am
well that's when you use Equ->String(... :P
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 16, 2010, 09:45:09 am
That can work inside Output(?

You seem to always find a solution to everything I post. Could you actually post your entire source code on how to display STO character inside a BASIC program on the home screen?

EDIT: Actually that works, thanks. I have bad memories about Equ>String, though O.O (See the TI-OS glitches section)
Title: Re: Fun with strings!
Post by: c.sprinkle on December 16, 2010, 10:37:55 am
MathPrint OSes are just a bunch of glitches.  >:(
Title: Re: Fun with strings!
Post by: lookitsan00b on December 16, 2010, 11:43:05 am
That can work inside Output(?

You seem to always find a solution to everything I post. Could you actually post your entire source code on how to display STO character inside a BASIC program on the home screen?

EDIT: Actually that works, thanks. I have bad memories about Equ>String, though O.O (See the TI-OS glitches section)

actually, you have to have the " and/or -> already in a string var, then you can treat it just like a normal string. Any other way = syntax error. So yeah you have to include the string var with your program.

MathPrint OSes are just a bunch of glitches.  >:(

Hey! thats not true! take it back! where would we be without fnInt(, remainder(, randintnorep(, fractions, and the ability to scroll up and delete your previous entries (not to mention the CLASSIC token/mode :P)?  TI could've just made the OS ALL mathprint, after all... no mode setting to go back.

Wow. When I put it that way, it makes me almost LIKE TI O.O
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 16, 2010, 09:27:21 pm
Yeah but the issue with MathPrint is that it breaks compatibility with old BASIC programs sometimes, some ASM programs, is not as stable and MathPrint mode is very slow. Try to scroll down the Y= menu, for example. To run any homescreen BASIC game, you have to disable MathPrint, else the game run 60% slower.

MathPrint is great in a math point of view, but in a TI community development point of view, it's a nightmare. KermMartian spent days trying to make Doors CS 7.1 OS 2.53 MP compatible...

Also I rated down your post because it was rude. If you're a OS 2.53 MP fanboy, it doesn't mean you have to attack others that dislike it, especially considering they have huge reasons to dislike it, like you have reasons to like it.

MathPrint OSes are just a bunch of glitches.  >:(
Yeah but actually MathPrint at least doesn't have that one Equ>String glitch I mentionned.
Title: Re: Fun with strings!
Post by: AngelFish on December 16, 2010, 10:14:28 pm

Hey! thats not true! take it back! where would we be without fnInt(, remainder(, randintnorep(, fractions, and the ability to scroll up and delete your previous entries (not to mention the CLASSIC token/mode :P)?

Um, exactly where we were before mathprint :P
Title: Re: Fun with strings!
Post by: DJ Omnimaga on December 16, 2010, 10:54:09 pm
I wish TI just copied MathPrint from the TI-73 and implemented it on the 83+ and 84+ and added the ability to disable it. On the 73 it runs very fast, even faster than on the 84+, even if it's a slower processor.