how to compare two string with not equal to ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2021 10:02 AM
how to compare two string with not equal to ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2021 10:05 AM
<x> != <y>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2021 10:06 AM
Hi kajol,
Where are you stuck? What is your use case?
Generally we use the following script to compare two scripts:
var str1 = 'FirstString';
var str2 = 'SecondString';
if(str1==str2){
// If equal then this block will execute
}else{
// If unequal then this block will execute
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2021 03:53 AM
Hi Mahesh,
Can I compare using a variable?
Example:
var compare = ">";
if(10 compare 20) {
gs.print("10 > 20");
}
else {
gs.print("10 < 20");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2021 10:12 AM
You can use the js indexOf() function:
var string = "Hello world, welcome to the universe.";
var containsString = string.indexOf("welcome");
if(containsString == -1){
console.log('Does not contain');
} else {
console.log('Contains');
}
The containsString variable will return -1 if it does not contain.
https://www.w3schools.com/jsref/jsref_indexof.asp
MVP 2025 ✨