Number of occurences for a string pattern

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

makas12
Posts: 10
Joined: Tue Jun 30, 2015 12:03 pm

Number of occurences for a string pattern

Postby makas12 » Mon Feb 29, 2016 9:20 am

Is there a function to count number of occurrences of a string pattern in string list? Before writing a function, I want to know if there is out-of-the-box functionality to compute number of occurrences of a string pattern in a string list? Thanks,

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13584
Joined: Tue Sep 16, 2008 5:38 pm

Re: Number of occurences for a string pattern

Postby EViews Gareth » Mon Feb 29, 2016 9:33 am

No.

mamo
Posts: 205
Joined: Wed Nov 07, 2012 9:11 am

Re: Number of occurences for a string pattern

Postby mamo » Fri Mar 04, 2016 2:13 am

Hi,
here is a (case-sensitive) workaround in one line.
Let %s1 denote the shorter string occuring zero or more times in the longer string %s2. The code

Code: Select all

(@strlen(%s2)-@strlen(@replace(%s2,%s1,"")))/@strlen(%s1)
Best, mamo


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests