gpt4 book ai didi

Using multiple SUBSTITUTE functions dynamically(动态使用多个替代函数)

转载 作者:bug小助手 更新时间:2023-10-25 20:36:44 31 4
gpt4 key购买 nike



Let's say I have a list of strings and I want to remove specific words from them. I can easily use multiple SUBSTITUTE functions, for example, this will remove the strings in B2, B3 and B4 from the string in A2:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,$B$2,""),$B$3,""),$B$4,"")

假设我有一个字符串列表,我想从其中删除特定的单词。我可以很容易地使用多个替换函数,例如,这将从A2:=Submit(A2,$B$2,“”),$B$3,“”),$B$4,“”中删除B2,B3和B4中的字符串


How can I make this dynamic so that when I add more terms to remove in the B column they'll be removed automatically from A2. I tried the following methods but they didn't work:

如何使其动态化,以便当我在B列中添加更多要删除的术语时,它们将自动从A2中删除。我尝试了以下方法,但都不起作用:


1 - add the B cells as an array
=SUBSTITUTE(A2,{$B$2:$B$4},"") or =SUBSTITUTE(A2,{$B$2,$B$3,$B$4},"")

1-将B单元格添加为数组=替换(A2,{$B$2:$B$4},“”)或=替换(A2,{$B$2,$B$3,$B$4},“”)


2 - Make a single condition

2--设定一个条件


cat|donkey|mouse

3 - Using Indirect and concatenate - I built the correct function as a string (using REPT and CONCATENATE) and tried to activate it with INDIRECT) but this also failed.

3-使用INDIRECT和CONCATENATE-我将正确的函数构建为字符串(使用REPT和CONCATENATE),并尝试使用INDIRECT激活它,但也失败了。


Here's the spreadsheet (Col A are the strings to clea, B are the words to remove, D is the manual method that works, F, H and K are the failed 3 attempts).
https://docs.google.com/spreadsheets/d/15u8qZ0xQkjvTRrJca6AInoQ4aPkijccouAETE4Gyr9I/edit#gid=0

以下是电子表格(A列是Clea的字符串,B是要删除的单词,D是有效的手动方法,F、H和K是失败的3次尝试)。Https://docs.google.com/spreadsheets/d/15u8qZ0xQkjvTRrJca6AInoQ4aPkijccouAETE4Gyr9I/edit#gid=0


更多回答
优秀答案推荐

In the 'Copy' of the tab I entered

在我输入的选项卡的‘副本’中


=ArrayFormula(IF(LEN(A2:A), REGEXREPLACE(A2:A, TEXTJOIN("|", 1, B2:B),),))

See if that works for you?

看看这对你是否管用?




EXPLANTION



  • LEN(A2:A) basically limits the output to the rows that a value in column A

  • REGEXREPLACE uses a regular expression to replace parts of the string. That regular expression is constructed by the TEXTJOIN function.

  • TEXTJOIN combines the text from the range B2:B, with a specifiable delimiter separating the different texts. Here the pipe character (which means 'or' in regex) is used. The second paramater of this function is set to TRUE (or 1) so that empty cells selected in the text arguments won't be included in the result.


REFERENCES




You can also try-

你也可以试着-


=TEXTJOIN(" ",TRUE,FILTER(SPLIT(A2," "),ISERROR(MATCH(SPLIT(A2," "),$B$2:$B$7,0))))


By using some newly introduced Google Sheet Formula, I have made myself a more generic formula

通过使用一些新推出的Google Sheet公式,我使自己成为了一个更通用的公式


=MAP(
targetRange,
LAMBDA(
input,
REDUCE(
input,
SPLIT("from1>to1%from2>to2%from3>to3","%"),
LAMBDA(input, regex,
REGEXREPLACE(
input,
REGEXEXTRACT(regex,"(.*)>"),
REGEXEXTRACT(regex, ">(.*)")
) ) ) ) )

The part SPLIT("from1>to1%from2>to2%from3>to3","%") could also be replaced dynamically as

也可以动态地替换分割部分(“from 1>to 1%from m2>to 2%from m3>to 3”,“%”)


BYROW(
subsTableRange,
LAMBDA(r, TEXTJOIN(">", 1, r)
)

更多回答

This works great! Can you please explain the way this works?

这真是太棒了!你能解释一下这是怎么回事吗?

Updated my answer to include a brief explanation and references to the functions used.

更新了我的答案,包括了对所用函数的简要说明和参考。

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

您的答案可以通过其他支持信息来改进。请编辑以添加更多详细信息,如引用或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com