Replace does not work as expected on strings

For questions regarding programming in the EViews programming language.

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

skan
Posts: 4
Joined: Fri Aug 14, 2020 2:17 am

Replace does not work as expected on strings

Postby skan » Tue Oct 20, 2020 6:33 am

Dear All,

how should replace work on strings? Please consider the following code:

wfcreate(wf="file") a 1 10
series foo_1=1
series bar_1=2
group _bar bar_*
%sn_bar=_bar.@seriesname(1)
%sn_foo=@replace(%sn_bar,"bar","foo")
group __result {%sn_foo} {%sn_bar}

The group "__result" should contain the series "foo_1" and "bar_1", instead of "bar_1" and "bar_1". Is this a bug?

Thank you!
skan

EViews Matt
EViews Developer
Posts: 583
Joined: Thu Apr 25, 2013 7:48 pm

Re: Replace does not work as expected on strings

Postby EViews Matt » Tue Oct 20, 2020 7:12 am

Hello,

The series name returned by _bar.@seriesname(1) is in uppercase, i.e., "BAR_1", and @replace uses case-sensitive matching. Either change the case of %sn_bar or of the target string "bar" and the code will work as intended.

skan
Posts: 4
Joined: Fri Aug 14, 2020 2:17 am

Re: Replace does not work as expected on strings

Postby skan » Tue Oct 20, 2020 9:04 am

Great! Thank you!

skan


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests