What is logic for 'contains but not necessarily equals'

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.
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
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.
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
you can also do javascript string search==> str.search() and check for value -1 if null
 

crazyflx

Новичок
Регистрация
23.08.2011
Сообщения
19
Благодарностей
8
Баллы
0
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.
 

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