{"id":203,"date":"2009-02-26T00:00:13","date_gmt":"2009-02-26T07:00:13","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=857"},"modified":"2009-02-26T00:00:13","modified_gmt":"2009-02-26T07:00:13","slug":"stringindexof","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=203","title":{"rendered":"String.indexOf()"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar words:String = &quot;one two three four five&quot;;\r\n\r\ntrace(&quot;two: &quot;, words.indexOf(&quot;two&quot;));\r\n\r\nvar letters:String = &quot;abcd&quot;;\r\n\r\ntrace(&quot;d: &quot;,letters.indexOf(&quot;d&quot;));\r\n\r\ntrace(&quot;z: &quot;,letters.indexOf(&quot;z&quot;));\r\n\r\n\/*\r\noutputs:\r\ntwo:  4\r\nd:  3\r\nz:  -1\r\n*\/\r\n<\/pre>\n<p>indexOf() searches a string for another string and returns an index&#8230; in line 3 above, I search the <em>words<\/em> string for the smaller string &#8220;two&#8221; and indexOf() gives me the index of the letter &#8220;t&#8221;. If indexOf() doesn&#8217;t find anything it will return -1 (as in the case of line 9).<\/p>\n<p>I seem to recall using this in some unexpected places. I&#8217;ll see if I can dig up an example over the next few days.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var words:String = &quot;one two three four five&quot;; trace(&quot;two: &quot;, words.indexOf(&quot;two&quot;)); var letters:String = &quot;abcd&quot;; trace(&quot;d: &quot;,letters.indexOf(&quot;d&quot;)); trace(&quot;z: &quot;,letters.indexOf(&quot;z&quot;)); \/* outputs: two: 4 d: 3 z: -1 *\/ indexOf() searches a string for another string and returns an index&#8230; in line 3 above, I search the words string for the smaller string &#8220;two&#8221; and indexOf() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,21],"tags":[3,4],"class_list":["post-203","post","type-post","status-publish","format-standard","hentry","category-string-manipulation","category-strings","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}