Page 1 of 1

Replace does not work as expected on strings

Posted: Tue Oct 20, 2020 6:33 am
by skan
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

Re: Replace does not work as expected on strings

Posted: Tue Oct 20, 2020 7:12 am
by EViews Matt
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.

Re: Replace does not work as expected on strings

Posted: Tue Oct 20, 2020 9:04 am
by skan
Great! Thank you!

skan