Hi,
Could someone help me understand why I'm failing at this?
I have a string with these contents:
_GDP_STUFF_158
_GDP_STUFF_20
_CPI_STUFF_120
_CPI_STUFF_1
I'd like to make a new string consisting only of two elements: "_GDP_STUFF_" and "_CPI_STUFF_". My strategy was to use @wreplace to replace the numbers with nonsense that I would then use @wdrop to get rid of, and then use @wunique to get me only unique elements.
If anyone has a more elegant way they've done something similar, please let me know. But outside of that, I am failing trying to get @wreplace to work.
Assuming the name of mu string is "stringname," I am trying things like:
string stringname=@wreplace(stringname,"_*_*_*","_*_*_00")
to no avail.
Anyone have any guidance? Thank you!
replacing text in a string
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: replacing text in a string
You can't replace a wildcard with something.
In your examples, I think something like:
should work
In your examples, I think something like:
Code: Select all
create u 10
string stringname = "_gdp_stuff_158"
string stringname1 = @left(stringname, @instr(stringname, "_", 3)) + "00"
show stringname1
should work
Follow us on Twitter @IHSEViews
Re: replacing text in a string
Forgive me Gareth but I just realized it won't work. I posed my problem incorrectly; apologies.
My starting string is this: "_GDP_OLDSTUFF_18 _GDP_OLDSTUFF_122 _GDP_NEWSTUFF_50"
and the output i need is this string:
"_GDP_OLDSTUFF_ _GDP_NEWSTUFF_"
so what i need is just way to drop the numbers and retain every unique element once I ignore the numbers.
if I use your approach i get
"_GDP_OLDSTUFF_00" -- so I lose "_GDP_NEWSTUFF_"
sorry to follow up on it, but this is surprisingly vexing. if you have any other ideas i would be very grateful!
My starting string is this: "_GDP_OLDSTUFF_18 _GDP_OLDSTUFF_122 _GDP_NEWSTUFF_50"
and the output i need is this string:
"_GDP_OLDSTUFF_ _GDP_NEWSTUFF_"
so what i need is just way to drop the numbers and retain every unique element once I ignore the numbers.
if I use your approach i get
"_GDP_OLDSTUFF_00" -- so I lose "_GDP_NEWSTUFF_"
sorry to follow up on it, but this is surprisingly vexing. if you have any other ideas i would be very grateful!
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: replacing text in a string
Loop through the words of your string using my replacement on each word one at a time.
Follow us on Twitter @IHSEViews
Re: replacing text in a string
haha. oh boy. it is clearly miller time ... thanks gareth... got a little stuck there!
Who is online
Users browsing this forum: No registered users and 48 guests