Page 1 of 1

@wreplace(%eq,"*[*", "*(*")

Posted: Wed Aug 26, 2015 12:12 pm
by tvonbrasch
Hi

I want to replace [ with ( in a string. But this does not work with the code:

%eq=@wreplace(%eq,"*[*", "*(*")
%eq=@wreplace(%eq,"*]*", "*)*")

where the string %eq= "0*U65+d(LOG(U65),1)=UR65+Urcon65+ucon65(1)+ucon65[2]*d(LOG(U65(-2) ) ,1)+ucon65[3]*d(LOG(U65(-10)),1)+ucon65[4]*d(LOG(x65),1)+ucon65[5]*(LOG(U65(-1)/x65(-1))-0.2*LOG(w65(-1)/pF65(-1))-0.75*LOG(pM65(-1)/pF65(-1))+0.0055757*TID)+ucon65[6]*DKV1+ucon65[7]*DUM901"

what am i doing wrong?
THomas

Re: @wreplace(%eq,"*[*", "*(*")

Posted: Wed Aug 26, 2015 1:06 pm
by EViews Gareth
@wreplace replaces words. You want @replace

Re: @wreplace(%eq,"*[*", "*(*")

Posted: Thu Aug 27, 2015 12:34 am
by tvonbrasch
Hi

Thanks for your reply.
What do you mean by replacing words, in the help menu it states
Example:
@wreplace("ABC AB", "*B*", "*X*")
replaces all instances of “B” with “X”, returning the string “AXC AX”.

which is not a replacement of words...?

The command

show @replace("0.0055757*TID+ucon65[6]","*TID*", "*(*") also yields "0.0055757*TID+ucon65[6]"
(but the command %eq=@wreplace("0.0055757*TID+ucon65[6]","*[1]*", "*(1)*") works for some reason)

Note that the commands
show @replace("0.0055757*TID+ucon65[6]","*TID*", "*TEST*") yields "0.0055757*TID+ucon65[6]", while

show @wreplace("0.0055757*TID+ucon65[6]","*TID*", "*TEST*") yields "0.0055757*TEST+ucon65[6]"

I am a bit confused about these commands....?

Neither of them manages to replace [ with ( ?

Can you please take another look at it?
Thomas

Re: @wreplace(%eq,"*[*", "*(*")

Posted: Thu Aug 27, 2015 1:00 am
by trubador
The following would yield the same output:

Code: Select all

@wreplace("0.0055757*TID+ucon65[6]","*[*", "*(*") @replace("0.0055757*TID+ucon65[6]","[", "(")
It does not work in your case because @wreplace considers %eq as a whole word as there are no spaces in it. And therefore it will only change the first instance (...ucon65[2]...). Do not use * or ? in @replace, since it does not look for patterns as @wreplace do.

Re: @wreplace(%eq,"*[*", "*(*")

Posted: Thu Aug 27, 2015 9:41 am
by tvonbrasch
ah, thanks, that explains it :-)