Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




search() - FUNCTION


search() Function


The search() Function is used to find a substring from the String. It gives us the position of the substring.


Example :



<html>
<body>  
<script>

	var x = "Hello Beautiful World"
	var y = x.search("Beautiful")
	document.write("The substring is located at the position ",y)
    
</script>      
</body>
</html>


Output :



  The substring is located at the position 6

In the above code, we have declared a String Hello Beautiful World and assigned it to a variable x.


x = "Hello Beautiful World"
java_Collections


And we would be searching the substring Beautiful, from the String, Hello Beautiful World.


So, we have used the search() Function to find the substring Beautiful.


y = x.search("Beautiful")

And what search() Function does is, goes to the String Hello Beautiful World and searches for the position of the substring Beautiful.

java_Collections

And finds the substring Beautiful in the 6th position. And the position (i.e. 6) is stored in variable y.

java_Collections

And thus prints the position.


document.write("The substring is located at the position ",y)

Output :



  The substring is located at the position 6