本文介绍了从另一个列表中的一个列表中查找字符串并找到返回的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在已经确定 roo是ListA所在行中我的房间的一部分。 我在该示例的基础上分配了是,而不是在ListA和ListB之间存在这种匹配时为true。

The "Flags only" example provided by Matchlists/tables in power query already determines that "roo" is part of ListA’s row that has "in my room." I built on the example to assign "yes," instead of true when there is such a match between the ListA and ListB.

我想做的是用ListB中的实际值替换是,例如,值 roo。我试图简单地用wordB代替是,但是我得到一个错误,即无法识别wordB。

What I’d like to do is to replace "yes" with the actual value from ListB — the value "roo," for instance. I tried to simply substitute wordB for "yes" but I got an error that wordB wasn’t recognized.

let
    ListA = {"help me rhonda",  "in my room", "good vibrations", "god only knows"},
    ListB = {"roo", "me", "only"},
    contains_word=List.Transform(ListA, (lineA)=>if List.MatchesAny(ListB, (wordB)=>Text.Contains(lineA, wordB)) = true then "yes" else "no")
in
    contains_word

当前查询的结果如下:

    List
1   yes
2   yes
3   no
4   yes

我希望查询结果为:

    List
1   roo
2   me
3
4   only

有什么想法吗?

(ps我对Power Query非常了解/ M)

(p.s. I'm extremely new to Power Query / M)

谢谢

推荐答案

我会这样做:

let
    ListA = {"help me rhonda",  "in my room", "good vibrations", "god only knows"},
    ListB = {"roo", "me", "only"},
    contains_word=List.Transform(ListA, (lineA)=>List.Select(List.Transform(ListB, (wordB)=>if Text.Contains(lineA, wordB) = true then wordB else null), (x)=>x <> null){0}?)
in
    contains_word

[edited]

这个想法是使用List.Transform两次:内部一个更改列表B只保留匹配的值。然后第一个非null值的最新值替换列表A(外部List.Tramsform)中的字符串。

The idea is to use List.Transform twice: inner one changes list B to leave only matching values. Then 1st non-null of latest replaces string from list A (outer List.Tramsform).

这篇关于从另一个列表中的一个列表中查找字符串并找到返回的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:00
查看更多