Posted: 5/20/2010 3:16:09 AM
Hi,
I have a string now I need to find whether that string contains a particular word or not but I am not able to find .contains in javascript? Yes I know how to use in c# but not in javascript . Please help
Posted: 5/21/2010 3:10:57 PM
Go with indexOf. I have made a sample below for you try it.
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> var inputString = 'Hello this is a test string'; //test input var wordToFound = 'this'; if (inputString.indexOf(wordToFound) == -1) { alert(wordToFound + ' Not Found'); } else { alert(wordToFound + ' Found'); } //Now let's do another test wordToFound = 'how'; if (inputString.indexOf(wordToFound) == -1) { alert(wordToFound + ' Not Found'); } else { alert(wordToFound + ' Found'); } </script> </head> <body> </body> </html>