Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I would like to replace a sub string based on a wildcard match. How would I do this? The function "Replace" does not seem to accept wildcards, but conceptually I would like to be able to do something like this:
Replace(MyField, 'b.d', 'XYZ'))
Then examples of field values and results results would look like this:
Field Value | Result |
---|---|
abcde | aXYZe |
abfde | aXYZe |
abde | abde |
axcde | axcde |
so only bd get replaced when there is something in the middle of it?
I think you will need to use the substring/index function and concatenate the XYZ in the middle of it deleting bd when there is something between bd
OK, but how would I actually do that? It doesn't seem like the index function accepts wildcards either.
I think you could use mapsubstring() for it. Here two examples what is meant:
Re: Passing parameter strings that contain special characters
Re: Wildcard Lookup between two tables
- Marcus
You can use a macro to find and replace using regular expressions:
Yes, it is a bit bloat but works:
replacemap:
Mapping
load * Inline
[
ori,new
bad,b@d
bbd,b@d
bcd,b@d
bfd,b@d
bxd,b@d
](delimiter is ',');
base:
Load * inline
[
Field
abcde
abfde
abde
axcde
eafgbxxdjk
eafgbxdjk
] (delimiter is '|');
Final:
Load
Field,
MapSubString('replacemap',Field) as replace_step,
replace(MapSubString('replacemap',Field),'@','NewString') as Final
Resident base;
drop table base;
G.
Hi Stefan,
It is wonderful. I didn't know about there is such opportunity to use RegExp in Sense.
G.
Well, I missed the QS part of the question, the link is related to QV. Need to check for QS.
So I know there is an opportunty to write subroutine in Sense, but you can't do the same with functions.
The editor returns with 'Unknown statement: Function'