Difference between revisions of "TI-BASIC:Strip A String"
(Initial automated import) |
(Automated @@ correction) |
||
Line 1: | Line 1: | ||
{{Template:TI-BASIC:Routine | {{Template:TI-BASIC:Routine | ||
− | |picture= | + | |picture= |
|summary=Strip a string of its spaces on the left and right. | |summary=Strip a string of its spaces on the left and right. | ||
|input=''Ans'' - The string you want to strip | |input=''Ans'' - The string you want to strip | ||
Line 6: | Line 6: | ||
|variable=Ans, Str1 | |variable=Ans, Str1 | ||
|compatibility=TI-83/84/+/SE | |compatibility=TI-83/84/+/SE | ||
− | |author= | + | |author= |
− | |authors= | + | |authors= |
− | |url= | + | |url= |
|download=[file stripstring.zip] | |download=[file stripstring.zip] | ||
}} | }} |
Latest revision as of 22:10, 24 February 2016
Routine Summary
Strip a string of its spaces on the left and right.
Inputs
Ans - The string you want to strip
Outputs
Str1 - The stripped string
Variables Used
Ans, Str1
Calculator Compatibility
TI-83/84/+/SE
Download
:While " "=sub(Ans,1,1) or " "=sub(Ans,length(Ans),1 :sub(Ans,1+(" "=sub(Ans,1,1)),length(Ans)-1→Str1 :End
With our string stored in Ans, we check to see if there is a space at the beginning or end of the string. If there is a space, then we remove it by storing the substring of the string that doesn't include the first character (for a space at the beginning) or the last character (for a space at the ending), and store the new string to Str1.
At the same time, the new string is stored to Ans, which is what we use next time through the While loop. The loop gets repeated over and over again until we have stripped all of the spaces from the beginning and end of the string. If you only want to remove spaces on one side of the string, edit the first and second lines accordingly.
Using Ans allows us to not have to use another string variable, since Ans can act like a string and it gets updated accordingly, and Ans is also faster than a string variable. In addition, by storing the string to Str1 inside the loop, we avoid having to add an additional storage to the routine.
We store the string to a more permanent variable (in this case, Str1) for future use. When you are done using Str1, you should clean it up at the end of your program.