Check whether the string has any value in the array.

tsoct
Tera Guru

Hello, everyone.
The script should check if the string contains any of the tags. However, the script below returns "not found" even when the tag is contained in the string.

 

var excludedtags ='[URGENT],[JUNK],[DUPLICATE],[IGNORE]';
var subject: 'HELP NEEDED - [[URGENT] Your account is temporarily blocked]';
               var outputStr = excludedtags.split(',');
               var tagArr = [];
               for (var i = 0; i < outputStr.length; i++) {
                   tagArr.push('"' + outputStr[i] + '"');
               }
               tagArr.join();  //return "[URGENT]","[JUNK]","[DUPLICATE]","[IGNORE]"
               for (var i2 = 0; i2 < tagArr.length; i2++) {
                   if (subject.indexOf(tagArr[i2]) > -1) {
                       gs.info('found ' + tagArr[i2]);
                   } else {
                       gs.info(' not found ' + tagArr[i2]);
                   }
               }

//result:
*** Script:  not found "[URGENT]"
*** Script:  not found "[JUNK]"
*** Script:  not found "[DUPLICATE]"
*** Script:  not found "[IGNORE]"
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

These are not found as the subject does not contain the tag in quotes.  Change your push to this and it will work, also correcting the var subject typo : instead of =

                   tagArr.push(outputStr[i]);

View solution in original post

2 REPLIES 2

Mark Manders
Mega Patron

Can you check if this works:

var excludedTags = '[URGENT],[JUNK],[DUPLICATE],[IGNORE]';
var subject = 'HELP NEEDED - [[URGENT] Your account is temporarily blocked]';

var tagArray = excludedTags.split(','); // Split the excluded tags into an array

for (var i = 0; i < tagArray.length; i++) {
    if (subject.indexOf(tagArray[i]) > -1) {
        gs.info('found ' + tagArray[i]);
    } else {
        gs.info('not found ' + tagArray[i]);
    }
}

 

I think wrapping the tags in quotes when pushing them into the array is the issue.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Brad Bowman
Kilo Patron
Kilo Patron

These are not found as the subject does not contain the tag in quotes.  Change your push to this and it will work, also correcting the var subject typo : instead of =

                   tagArr.push(outputStr[i]);