[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  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] Refresh page


Posted by Sirius096   (12 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Sirius096   (12 posts)  [Biography] bio
Date Reply #2 on Fri 01 Jun 2007 04:03 AM (UTC)
Message
Thanks :)
[Go to top] 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.


10,877 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]