Containing sub string in string Using JavaScript
Check Containing sub string in string Using JavaScript
we are easily find sub string in a particular string variable by the javasrcipt code in asp.net programming.In the Asp.net programming we know that we write JS code in to <head> tag.Find Sub string form string using JS
This function use to solve this by the java script language
if ('Hello, World!'.indexOf('orl') !== -1)
alert("The string 'Hello World' contains the substring 'orl'!");
else
alert("The string 'Hello World' does not contain the substring 'orl'!");
here we give a code segment with if condition to finding the sub string.
now we give full function for getting sub string.Function for getting present of sub string in String
function strstr(str, substr) {
if (str.indexOf(substr) !== -1)
alert("The string ' " + str + " ' contains the substring ' " + substr + " '!");
else
alert("The string ' " + str + " ' does not contain the substring ' " + substr + " '!");
}
var str = prompt("What is the string?");
var substr = prompt("What is the substring?");
strstr(str, substr);
some time we see that the developer want to get only sub title of the name and show it on web page but if the name has only first name then developer want to show only first name. so this type of problem can easily solved by java script code or client side.
Related JavaScript Post
Other Post :
Reference: