What is logic for 'contains but not necessarily equals'

  • Автор темы Автор темы jp1
  • Дата начала Дата начала

jp1

Client
Регистрация
23.01.2011
Сообщения
234
Реакции
2
Баллы
0
I know == is equivalent, but what is contains?

Like, the string is equivalent to 'x'

So you write 'string'=='x'

But what do you write when you're looking for the string 'has x in part of it' and/or is equivalent.

I'm looking for a 'string x' to give true when asked if 'x' is in it.

thanks.
 
there is no such LOGIC operator.
you might e.g. check with regexp, and compare result with empty string "{regexp-result}"!=""
there is also method indexOf() with JavaScript you might use on string.
 
you can also do javascript string search==> str.search() and check for value -1 if null
 
you can also do javascript string search==> str.search() and check for value -1 if null

This is probably your best solution. If you aren't sure what he means, open up project maker and then open up the "Javascript Tester" (it's next to the Macros Editor button in the Ribbon).

Paste this into it:

var findme = "x";
var StringtoLookIn = "abcdefghijklmnopqrstuvwxyz"
StringtoLookIn.search(findme);

Then press play. It will return "23" as the result (which is where "x" appears in the "stringtolookin"). If you remove the letter "x" from "stringtolookin" and press play, the result will be "-1" which means it couldn't find it.
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)