Home > DeveloperSection > Forums > How to search for a substring in a string in Javascript?
Anoop Singh
Anoop Singh

Total Post:12

Points:84
Posted on    February-28-2011 2:18 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 1320  View(s)
Rate this:
Hi,

I'm new to Javascript and have requirement where I have to check whether particular sub string exist in a string or not.

Thanks in advance.


Alex R
Alex R

Total Post:40

Points:280
Posted on    February-28-2011 2:26 AM

Hi Anoop,

You can search sub string in a string using search() method of Javascript

Here is the example,
        

var mainString = 'Hello world';

if (mainString.search('world') >= 0)

       alert('Exist');

Hop this will solve your problem.


Don't want to miss updates? Please click the below button!

Follow MindStick