有没有一种方法可以检查字符串中的字符是否包含在字符数组中-NO VBA

时间:2020-01-22 23:16:43

标签: excel

我在excel中有很长的字符串。我需要检查字符串的每个char是否匹配char数组。 例如:

%dw 2.0
output application/json
var grade = 1
var topic = "math"
---
flatten( 
    payload map (alumn, order) -> 
        (alumn.marks pluck ((value, key, index) -> 
            {
                name: alumn.name, 
                grade: alumn.grade, 
                result:value, 
                topic: key
            })
        )
) // restructure the list to one result per element
filter ((item, index) -> (item.grade == grade)) // filter by grade
maxBy ((item) -> item.result) // get the maximum result

我尝试过查找或匹配,但它们只是寻找第一次出现的情况,....

2 个答案:

答案 0 :(得分:1)

对于区分大小写的方法,如果具有CONCAT函数,则可以使用以下命令:

(对于不区分大小写的情况,将FIND替换为SEARCH

=IF(OR(ISERR(FIND(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1),1)),1),CONCAT(" ",AllowedChars)))),"check failed", "check ok")

如果您没有CONCAT函数,请在公式中将其替换为允许字符的简单字符串:

=IF(OR(ISERR(FIND(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1),1)),1)," iamnotItersd"))),"check failed", "check ok")

,请注意,某些早期版本的Excel将要求您在按下 enter 的同时按住 ctrl + shift 来确认此数组公式。如果正确执行此操作,Excel会在公式栏中显示的公式周围放置括号{...}

  • MID(…函数创建测试字符串中各个字符的数组
  • FIND然后对测试字符串中的所有字符与FIND中的字符进行区分大小写的AllowedChars
  • 如果找不到字符,
  • FIND将返回#VALUE!错误。
  • 如果匹配失败,
  • OR(ISERR(…将返回TRUE

编辑 的进一步说明:

  • ISERR(…将返回布尔数组{FALSE,FALSE,FALSE,FALSE,TRUE, … },具体取决于每个FIND是否返回许多#VALUE!错误

  • OR对该数组求值,如果有任何错误,则返回TRUE

其中AllowedChars是指存储允许字符的范围。

CONCAT会忽略范围内的空单元格,因此我们必须将空格添加为参数之一。

enter image description here

答案 1 :(得分:0)

使用一个范围内可接受字符的 UNIQUE 列表(我使用D1:D10),可以比较删除每个字符的差异之和与不带空格的字符串长度的总和:

['@babel/preset-typescript', { allExtensions: true, isTSX: true }], ['@babel/preset-react'],

此公式忽略大小写,并且列表必须是允许的字符的唯一列表。 // Process application JS with Babel. // The preset includes JSX, Flow, TypeScript, and some ESnext features. { test: /\.(js|mjs|jsx|ts|tsx)$/, include: [paths.appSrc, ...paths.appLernaModules], loader: require.resolve('babel-loader'), options: { customize: require.resolve('babel-preset-react-app/webpack-overrides'), presets: [// ADD THESE ['@babel/preset-typescript', { allExtensions: true, isTSX: true }], ['@babel/preset-react'], ], plugins: [ [ require.resolve('babel-plugin-named-asset-import'), { loaderMap: { svg: { ReactComponent: '@svgr/webpack?-svgo,+titleProp,+ref![path]', }, }, }, ], ], // This is a feature of `babel-loader` for webpack (not Babel itself). // It enables caching results in ./node_modules/.cache/babel-loader/ // directory for faster rebuilds. cacheDirectory: true, // See #6846 for context on why cacheCompression is disabled cacheCompression: false, compact: isEnvProduction, }, }, =SUMPRODUCT(LEN(A1)-LEN(SUBSTITUTE(A1,$D$1:$D$10,"")))+1 = LEN(SUBSTITUTE(A1," ","")) 与Excel看到的相同,并且列表中只能有一个。

enter image description here

相关问题