Saturday, October 10, 2020
Count number of X strings in text - using length and replace
You have often to count number of occurrences of one string X in text.
You can use only two methods to do that.
Here is example for PL/SQL, you can use this trick in all languages just use right length and replace function. X is 'T' and the text is 'TEXT'
count := (length('TEXT')-length( replace('TEXT','T','' ))) / length('T')
result is 2
