<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=TI-BASIC%3AInstring</id>
	<title>TI-BASIC:Instring - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=TI-BASIC%3AInstring"/>
	<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=TI-BASIC:Instring&amp;action=history"/>
	<updated>2026-06-17T18:40:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=TI-BASIC:Instring&amp;diff=659&amp;oldid=prev</id>
		<title>Maintenance script: Initial automated import</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=TI-BASIC:Instring&amp;diff=659&amp;oldid=prev"/>
		<updated>2016-02-24T18:12:12Z</updated>

		<summary type="html">&lt;p&gt;Initial automated import&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Template:TI-BASIC:Command&lt;br /&gt;
|picture=INSTRING.GIF&lt;br /&gt;
|summary=Finds the first occurrence of a search string in a larger string.&lt;br /&gt;
|syntax=inString(&amp;#039;&amp;#039;haystack&amp;#039;&amp;#039;, &amp;#039;&amp;#039;needle&amp;#039;&amp;#039;, &amp;#039;&amp;#039;starting point&amp;#039;&amp;#039;)&lt;br /&gt;
|location=This command can only be found in the Catalog. Press:&lt;br /&gt;
# 2nd CATALOG to access the command catalog&lt;br /&gt;
# I to skip to command starting with I&lt;br /&gt;
# scroll down to find inString( and select it&lt;br /&gt;
|compatibility=TI-83/84/+/SE&lt;br /&gt;
|size=2 bytes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The inString( command searches a string for occurrences of a smaller string (similar to the Find feature on a computer), and returns the first such occurrence.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;source string&amp;#039;&amp;#039; is the string you want to search through; the &amp;#039;&amp;#039;search string&amp;#039;&amp;#039; is the substring you want to find. inString( will return the index of the first letter of the first occurrence of the search string found, or 0 if the search string is not present. For example:&lt;br /&gt;
&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;BASIC&lt;br /&gt;
 	4&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;TI&lt;br /&gt;
 	1&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;I&lt;br /&gt;
 	2&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;ELEPHANT&lt;br /&gt;
 	0&lt;br /&gt;
&lt;br /&gt;
You can also provide the optional &amp;#039;&amp;#039;starting point&amp;#039;&amp;#039; argument, 1 by default, that will tell the command where it should start looking. If you provide a value higher than 1 here, the command will skip the beginning of the string. This can be used to find where the search string occurs past the first occurrence. For example:&lt;br /&gt;
&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;I&lt;br /&gt;
 	2&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;I&amp;quot;,2&lt;br /&gt;
 	2&lt;br /&gt;
 :inString(&amp;quot;TI-BASIC&amp;quot;,&amp;quot;I&amp;quot;,3&lt;br /&gt;
 	7&lt;br /&gt;
&lt;br /&gt;
= Advanced Uses =&lt;br /&gt;
&lt;br /&gt;
You can use inString( to convert a character to a number. For example:&lt;br /&gt;
&lt;br /&gt;
 :inString(&amp;quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;quot;,Str1→N&lt;br /&gt;
&lt;br /&gt;
Assuming Str1 is one character long and contains a capital letter, N will hold a value of 1-26 that corresponds to that letter. This value can then be stored in a real number, list, or matrix, where a character of a string couldn&amp;#039;t be stored. To get the character value of the number, you can use the [[TI-BASIC:Sub|Sub(]] command:&lt;br /&gt;
&lt;br /&gt;
 :sub(&amp;quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;quot;,N,1→Str1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;#039;&amp;#039;starting point&amp;#039;&amp;#039; argument of inString(, you can write a routine to return all occurrences of the search string in the source string:&lt;br /&gt;
&lt;br /&gt;
 :0→dim(L1&lt;br /&gt;
 :inString(Str0,Str1&lt;br /&gt;
 :Repeat not(Ans&lt;br /&gt;
 :Ans→L1(1+dim(L1&lt;br /&gt;
 :inString(Str0,Str1,Ans+1&lt;br /&gt;
 :End&lt;br /&gt;
&lt;br /&gt;
If the search string is not found, this routine will return {0} in L1. If it is found, the result will be a list of all the places the string was found.&lt;br /&gt;
&lt;br /&gt;
= Optimization =&lt;br /&gt;
&lt;br /&gt;
The inString( command can replace checking if a string is one of a number of values. Just put all the values in a string, one after the other, and try to find the string to be checked in the string of those values:&lt;br /&gt;
&lt;br /&gt;
 :If Str1=&amp;quot;.&amp;quot; or Str1=&amp;quot;,&lt;br /&gt;
 can be&lt;br /&gt;
 :If inString(&amp;quot;.,&amp;quot;,Str1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Be careful, because if Str1 were &amp;quot;.,&amp;quot; in the above example, this would also be treated like &amp;quot;.&amp;quot; or &amp;quot;,&amp;quot;. If this is a problem, you can separate the values you want to check for by a character you know can&amp;#039;t be in the string:&lt;br /&gt;
&lt;br /&gt;
 :If Str1=&amp;quot;HELLO&amp;quot; or Str1=&amp;quot;HI&lt;br /&gt;
 can be&lt;br /&gt;
 :If inString(&amp;quot;HELLO,HI&amp;quot;,Str1&lt;br /&gt;
&lt;br /&gt;
(assuming a comma would never be in Str1, and words like &amp;quot;HELL&amp;quot; or &amp;quot;I&amp;quot; are also impossible)&lt;br /&gt;
&lt;br /&gt;
= Error Conditions =&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;[[TI-BASIC:Errors#domain|ERR:DOMAIN]]&amp;#039;&amp;#039;&amp;#039; is thrown if &amp;#039;&amp;#039;starting point&amp;#039;&amp;#039; is not a positive integer (it&amp;#039;s okay, though, if it&amp;#039;s bigger than the length of the string).&lt;br /&gt;
&lt;br /&gt;
= Related Commands =&lt;br /&gt;
&lt;br /&gt;
* [[TI-BASIC:Expr|Expr(]]&lt;br /&gt;
* [[TI-BASIC:Length|Length(]]&lt;br /&gt;
* [[TI-BASIC:Sub|Sub(]][[Category:TI-BASIC]]&lt;br /&gt;
[[Category:TIBD]]&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>