字符串计数中的字符串 [英] String within a String Count
本文介绍了字符串计数中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个函数可以计算子字符串在较大字符串中出现的次数。
示例:恢复电话系统中的联系人
该函数需要告诉我你的出现在字符串中的次数;这将是2.
Is there a function that counts how many times a sub-string appears within the larger string.
Example: "Recover your contacts on your phone system"
The function would need to tell me how many times "your" appears in the string; which would be 2.
推荐答案
看看下面的simmilar问答帖。
< a href =http://www.postgresql.org/message-id/20091020172452.GA10593@tux> http://www.postgresql.org/message-id/20091020172452.GA10593@tux
希望它有所帮助。
Have a look at below simmilar Question-Answer thread.
http://www.postgresql.org/message-id/20091020172452.GA10593@tux
Hope it helps.
(长度(''在自己的世界中找到自己的方式') - 长度(替换( ''在自己的世界找到自己的方式',''你的'','''')))/长度(''你'')
...正确返回2.
这似乎比PostgreSQL网站上建议的更好...
长度(''在自己的世界找到自己的方式') - 长度(regexp_replace(''找到你自己的方式)在你自己的世界'','你的'','''',''g''))/长度(''在你自己的世界找到自己的方式')
...返回35(...这可能与表达式中的''g'有关,但我没有解释,我刚刚离开它。)
(Length(''Find your own way in your own world'') - Length(Replace(''Find your own way in your own world'',''your'',''''))) / Length(''your'')
...which correctly returned 2.
This seemed to work better than the one suggested on the PostgreSQL web site...
Length(''Find your own way in your own world'') - Length(regexp_replace(''Find your own way in your own world'',''your'','''',''g'')) / Length(''Find your own way in your own world'')
...which returns 35 (...this may have something to do with the ''g'' in the expression but it''s not explained do I just left it.)
这篇关于字符串计数中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文