Hi,

I am trying to generate two scalars to store numbers from the string "crmlaw_2014_2018" and "test_2015_2017"
The code I wrote is:

Code:
local       major crmlaw_2014_2018 test_2015_2017
foreach        i of local major{

            scalar a = strpos("`i'","_" )
            scalar b = substr("`i'",a+1,a+4)
            scalar c = substr("`i'",-4,.)
}
I expected that for "crmlaw_2014_2018", it will show a = 7 b=2014 c = 2018, but it actually shows a = 7 b=2014_2018 c = 2018.

Thank you for any insight for this!