不敏感且不完全匹配的字符串搜索数组 [英] Search Array of Strings with Non-sensitivity and Non-exact Match

查看:109
本文介绍了不敏感且不完全匹配的字符串搜索数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我对原始问题进行了一些更改,因为我的问题不是字符串中的逗号.

Notice: I have made a few changes to the original question as my problem was not with commas within string.

我有一个正在研究的函数,用于从包含要搜索的字符串的新数组中排除单元格值.我这样做是为了汇总

I have a function I've been working on to exclude a cell value from a new array that contains a string I am searching for. I am doing this in order to put together a list for .setHiddenValues, since .setVisibleValues is not supported/implemented yet.

为清楚起见,这是我的要求:

Here are my requirements for the sake of clarity:

当前正在工作:

  • 能够处理数字和字符串
  • 可以搜索小写和大写. visibleValueStr是用户输入的,因此不能太敏感.
  • colValueArr可能包含带逗号的字符串.
  • Able to handle numbers as well as strings
  • Can search for lowercase and uppercase. visibleValueStr is user inputted so it can't be so sensitive.
  • colValueArr may have strings with commas within.

仍在努力:

  • visibleValueStr可以是单个值或数组.
  • 区分大小写(苹果"与苹果"匹配)
  • 不完全匹配(苹果"匹配苹果和香蕉")
  • visibleValueStr can be a single value or array.
  • Case sensitivity("apple" to match "Apple")
  • Not exact matches("apple" to match "apple and banana")

这是我目前满足/未满足的条件的功能:

Here is the function I currently have with the above met/unmet conditions:

function getHiddenValueArray(colValueArr,visibleValueArr){
  var flatUniqArr = colValueArr.map(function(e){return e[0].toString();})
    .filter(function(e,i,a){
      return (a.indexOf(e.toString())==i && visibleValueArr.indexOf(e.toString()) == -1);
    })
  return flatUniqArr;
}

请让我知道我还需要什么其他信息.在我继续进行研究的同时,我将更新此问题.

Please let me know what other info I need. I will update this question as I continue to do my research in the meanwhile.

评论说明:

用户以HTML形式输入输入,并且变量作为visibleValueArr传递.

User inputs input(s) on HTML form and the variable is passed on as visibleValueArr.

使用Logger.log(visibleValueArr)时.

[apple, banana]

使用Logger.log(colValueArr)时.

[[Apple],[apple][apple][apple and banana],[apple],[banana, and apple],
  [apple, and banana],[orange],[orange, and banana],[kiwi],[kiwi, and orange],
  [strawberry]]

所以当我使用时:

SpreadsheetApp.newFilterCriteria().setHiddenValues(newArray).build();

newArray应该是隐藏值.在这种情况下,应为:

newArray should be the hidden values. In this case it should be:

  • 橙色
  • 猕猴桃
  • 猕猴桃和橙色
  • 草莓

基本上任何不包含visibleValueArr的内容.

Basically anything that does not contain what visibleValueArr is.

相反,它返回所有值,将其全部隐藏.

Instead, it returns all values back, hiding them all.

当我使用[Apple, Banana]时,"Apple"和"Banana"值应按原样保留在newArray中,但是"Apple和Banana"和"Apple和Banana"则不"

When I use [Apple, Banana] the "Apple" and "Banana" values are left out of newArray as they should be, but "Apple and Banana" and "Apple, and Banana" are not"

此外,我还想了解function(e,i,a)中的e,i,a代表什么.我试图在不同的地方应用.toLowerCase(),以查看是否可以解决部分问题,但是我不确定该在哪里进行.

In addition, I would also like to understand what the e,i,a in function(e,i,a) represent. I'm trying to apply .toLowerCase() in different places to see if that resolves part of my issue but I'm not sure where to do it.

推荐答案

问题:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆