反转“SEARCH”公式在Google表格中(数组公式)

huangapple go评论74阅读模式
英文:

Reversing "SEARCH" Formula in Google Sheet (Array Formula)

问题

SEARCH公式在Google表格中会返回单元格中特定字符的位置编号。

但我想知道,我们能否以类似的方式实现相反的效果?SEARCH会从左边计算单元格中的字符,但是否有任何方法可以从右边计算字符?

这是示例案例:

https://docs.google.com/spreadsheets/d/1vMAVqOyVCxTiwpBFUpCQcpTVgslda8aFh7AHs_5hP18/edit#gid=0

在这个示例中,我尝试手动给出最右侧空格(" ")的位置。所需结果有两种可能性。它可以是B列或C列。

是否有任何使用数组公式来实现这样的功能的方法?

英文:

SEARCH formula in google sheet will return a number of position of specific character in a cell.

But I wonder, can we do this similar thing but the other way around? SEARCH will count characters in a cell from left, but instead, is there any way to count the characters from right??

Here is the case sample:

https://docs.google.com/spreadsheets/d/1vMAVqOyVCxTiwpBFUpCQcpTVgslda8aFh7AHs_5hP18/edit#gid=0

In this sample, I tried to give the position of most right space (" ") manually, from the right. There are two possibility of the desired outcome. It can be either column B or column C.

Is there any way with array formula to be able to give such feats?

答案1

得分: 2

以下是翻译好的部分:

我认为要找到元素的数量,可以通过使用您的分隔符进行拆分来实现。我将使用LET来命名过程的不同部分。如果您不熟悉它,可以将其视为按步骤命名变量:

=LET(delim," ",
splitted,SPLIT(A2,delim),
splitted)

然后,通过计算先前拆分确定的“列”的数量,可以找到最后一个元素。使用INDEX和该数量,您将能够找到最后的子字符串:

=LET(delim," ",
splitted,SPLIT(A2,delim),
amount,COLUMNS(splitted),
INDEX(splitted,1,amount))

最后,所有这一切都是因为最后的“子字符串”及其长度+1,您将能够获取最后一个“分隔符”的位置:

=LET(delim," ",
splitted,SPLIT(A2,delim),
amount,COLUMNS(splitted),
LEN(INDEX(splitted,1,amount))+1)

作为一个数组公式,您可以使用BYROW或MAP:

=BYROW(A2:A,LAMBDA(string,
IF(string="", "",
LET(delim," ",
splitted,SPLIT(string,delim),
amount,COLUMNS(splitted),
LEN(INDEX(splitted,1,amount))+1))))
英文:

What I think is to find the amount of elements, by splitting by your delimiter. I'll use LET in order to name different parts of the process. If you're not familiar with it, think it as naming variables per step:

=LET(delim," ",
splitted,SPLIT(A2,delim),
splitted)

反转“SEARCH”公式在Google表格中(数组公式)

Then you find the last element, by counting the amount of "columns" determined by the prior splitting. With INDEX and that amount you'll be able to find the last substring:

=LET(delim," ",
splitted,SPLIT(A2,delim),
amount,COLUMNS(splitted),
INDEX(splitted,1,amount))

反转“SEARCH”公式在Google表格中(数组公式)

And, finally, all this is because the last "substring" and its length +1, you'll be able to get the position of the last "delimiter":

=LET(delim," ",
splitted,SPLIT(A2,delim),
amount,COLUMNS(splitted),
LEN(INDEX(splitted,1,amount))+1)

反转“SEARCH”公式在Google表格中(数组公式)

And as an arrayformula you can use BYROW or MAP:

=BYROW(A2:A,LAMBDA(string,
IF(string="","",
LET(delim," ",
splitted,SPLIT(string,delim),
amount,COLUMNS(splitted),
LEN(INDEX(splitted,1,amount))+1))))

反转“SEARCH”公式在Google表格中(数组公式)

答案2

得分: 2

这个问题可以很容易地使用正则表达式解决。

=ARRAYFORMULA(IFNA(LEN(REGEXEXTRACT(A2:A,".( .)"))))

英文:

This problem can be solved very easily with REGEX.

=ARRAYFORMULA(IFNA(LEN(REGEXEXTRACT(A2:A,".*( .*)"))))

huangapple
  • 本文由 发表于 2023年7月7日 08:08:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76633185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定