FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

JavaScript Tutorial: InStr in JavaScript

jawahar
10/1/2005 11:29:45 PM, Views: 21548
InStr(str, SearchForStr): Returns the location a character (charSearchFor) was found in the string str

InStr function written by: Steve Bamelis
InStr(strSearch, charSearchFor) : Returns the first location a substring (charSearchFor) found in the string strSearch.   (If the character is not found, -1 is returned.)
                                       
Requires use of:
    Mid function : http://www.expertsforge.com/Web-Development/Tutorial-86.asp


<script language="JavaScript">
function InStr(strSearch, charSearchFor)
{
            for (i=0; i < strSearch.length; i++)
            {
                  if (charSearchFor == Mid(strSearch, i, 1))
                  {
                        return i;
                  }
            }
            return -1;
}
</script>


Example:
alert(InStr("Hello_World", "_"))

Output:
5
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rating Booth
Avg Visitor Rating: Average Visitor Rating is 3.5 out of 5
Number of Ratings : 9 Votes
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
JavaScript RSS Feed
Most Popular Tutorial
Most Popular Solution
Top Rated
Top Rankers
Overall
1. jawahar (1400)
Yearly -2008
1. jawahar (200)
Expertsforge Sponsors
bnrtop