有没有一种简单的方法来计算一个文本字符串在另一个文本字符串中的出现次数? [英] Is there a simple way to count occurences of one text string within another text string?

查看:30
本文介绍了有没有一种简单的方法来计算一个文本字符串在另一个文本字符串中的出现次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以使用 PowerQuery 来计算一个文本字符串在另一个文本字符串中的出现次数?

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?

我知道我可以使用Text.Contains来确定字符串中是否出现lazy和dog,但我不知道确定多少次的简单方法它们发生了.

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

这篇关于有没有一种简单的方法来计算一个文本字符串在另一个文本字符串中的出现次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆