Is there a simple way to count occurences of one text string within another text string?

大憨熊 提交于 2019-12-10 19:21:27

问题


Is there a simple way, using PowerQuery, to count the occurences of a text string within another text string?

For instance, if I have the string, "The quick brown fox jumps over the lazy dog and the lazy dog doesn't notice," how would I easily determine that the words lazy and dog occur twice?

I know I can use Text.Contains to determine whether lazy and dog occur within the string, but I don't know a simple way to determine how many times they occur.


回答1:


You can split the text, using the search word as delimiter. The number of list items minus 1, is the number of occurrences.

let
    String = "The quick brown fox jumps over the lazy dog and the lazy dog doesn't notice,",
    Count = List.Count(Text.Split(String,"dog"))-1
in
    Count


来源:https://stackoverflow.com/questions/44268075/is-there-a-simple-way-to-count-occurences-of-one-text-string-within-another-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!