Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Jscript ➜ Can I do a check to see if a string contains x word?

Can I do a check to see if a string contains x word?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Sirius096   (12 posts)  Bio
Date Fri 01 Jun 2007 03:46 AM (UTC)

Amended on Fri 01 Jun 2007 03:58 AM (UTC) by Sirius096

Message
What I want to do, is store a whole line and run a check off that line to find out if it has 'x' word in it anywhere.

ie;
test (variable) = This is the line I want to check.

I want the if check to do this:
if (test <contains> "line") { <--- this is where I need the help
world.Note("blah");
}
else { (so if it doesnt contain 'line')
world.Note("not blah");
}
}

Heh... hope that is explained well enough. :/

-Siri
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Fri 01 Jun 2007 04:00 AM (UTC)
Message
Yes, to see if a string contains another string, use indexOf.

See:
http://www.w3schools.com/jsref/jsref_indexOf.asp

or google for "javascript indexOf" for plenty of other sites.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Sirius096   (12 posts)  Bio
Date Reply #2 on Fri 01 Jun 2007 04:03 AM (UTC)
Message
Thanks :)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,058 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.