To find the number of times a substring occurs in a string

Reply
Occasional Contributor
Posts: 17

To find the number of times a substring occurs in a string

Hi everyone,

I have a string variable, the observations of the variable are business scopes of firms. I want to find out from the business scope whether a firm produces commodities.

Primarily, I use index function to find the word "production" or "produce" and it works well. But I have problems, because in some observations "production facility",

"production skill" and "production" occur simultaneously. How could I decide whether these firms really produce commodites?

Thanks

Trusted Advisor
Posts: 1,228

Re: To find the number of times a substring occurs in a string

Hi,

This is up to you how you define production scopes. If you want to consider observations with production facility, production skill and production as business scope then you have count all of them in business scope.

Trusted Advisor
Posts: 1,137

Re: To find the number of times a substring occurs in a string

alternatively you are try to find two words something like index(variable,'production')>0 and index(variable,'commodities')>0, only if both the conditions are satisfied we can count it.

by pearl regular expressions it will be like

prxmatch('/production|produce/',variable)>0 and prxmatch('/commodities1|commodities2/',variable)>0

Thanks,

Jag

Thanks,
Jag
Ask a Question
Discussion stats
  • 2 replies
  • 201 views
  • 0 likes
  • 3 in conversation