SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript Tutorials
Popular Tutorials
Drop down list
Timer function
JavaScript Tutorials
String
Array
Date & Time
Form Validation
Event Handling
Math Functions
JavaScript Forum
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

 
 

String Search

WE can search for presence of a string inside a main string in client side JavaScript by using string.search function. If the search string is found inside the main string then it will return the position or the index of the location of the string. Note that the index of first letter is 0. If the string is not found inside the main string then it returns -1. We can check this and start building this example code here.

We are checking the presence of a sub string http:// inside a main string. We used if else condition checking to display a message based on the returned value. Here is the code.

var my_str="Welcome to http://www.plus2net.com"
var str="http://";
document.write (my_str.search(str));

if(my_str.search(str)==-1){
document.write(my_str.indexOf("Not Found inside string"));}
else{document.write("Found inside the string and the location of the sub string is ");
document.write (my_str.search(str));}
Further readings
Lower case text to Uppercase text
Uppercase letter to Lower case
Bold text letters using JavaScript
String Length
Character at a location using charat function
Indexof function
String Reverse function
search():Searching String inside another string
slice():Collecting part of a string using slice function
Domain and userid part of email address
Text box onBlur click event changing text case
 
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript