Author |
Message
|
fpg8 |
Posted: Mon Apr 09, 2012 6:23 am Post subject: Doubt about the esql function. |
|
|
Novice
Joined: 26 Mar 2012 Posts: 15
|
I want to replace a chain, for example: "1234AC56789" to "**********".
Probe with esql function:
replace ('123456789 ',' [A-Za-z0-9] * ',' * ')
It does not work.
Any help?
Thank you very much. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Mon Apr 09, 2012 6:27 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
mqjeff |
Posted: Mon Apr 09, 2012 6:42 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
fpg8 |
Posted: Mon Apr 09, 2012 6:49 am Post subject: |
|
|
Novice
Joined: 26 Mar 2012 Posts: 15
|
try this sentence but did not work:
SET numero_tarjeta_for = TRANSLATE (InputRoot.XMLNSC.ns: comprarContenidoTarjetaRequest.ns: numero_tarjeta, '[A-Za-z0-9] *', '*'); |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 09, 2012 6:53 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fpg8 wrote: |
try this sentence but did not work:
SET numero_tarjeta_for = TRANSLATE (InputRoot.XMLNSC.ns: comprarContenidoTarjetaRequest.ns: numero_tarjeta, '[A-Za-z0-9] *', '*'); |
As my associate pointed out, ESQL strings expressions are finite.
This is something the InfoCenter points out as well. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Apr 09, 2012 6:54 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
fpg8 wrote: |
try this sentence but did not work:
SET numero_tarjeta_for = TRANSLATE (InputRoot.XMLNSC.ns: comprarContenidoTarjetaRequest.ns: numero_tarjeta, '[A-Za-z0-9] *', '*'); |
The expression '[A-Za-z0-9]*' is a regular expression.
Does the documentation on the TRANSLATE function say that it accepts a regular expression?
What did your statement produce?
The documentation says that
Quote: |
each occurrence of any character that occurs in the search string being replaced by the corresponding character from the replace string |
So if you have a search string of 'A' and a replace string of '*', then all A's will be turned into *'s. If you have a search string of 'AB" and a replace string of '*&', then all A's will be turned into *'s and all B's will be turned into &'s. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Mon Apr 09, 2012 6:56 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
The OP is trying to do a variable string search, which is not supported by ESQL. One way to accomplish same is by calling the String class to perform the search and replacement. There may be other ways. Perhaps a code snippet could help here if you want to suggest another way? _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 09, 2012 6:59 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
There may be other ways. |
lancelotlinc wrote: |
Perhaps a code snippet could help here if you want to suggest another way? |
Suppling the correct replacement string to the function as my most worthy associate indicates is one. In which event the OP's code snippet should work a treat. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Esa |
Posted: Mon Apr 09, 2012 7:17 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Maybe something like this would do:
Code: |
SET numero_tarjeta_for = REPLICATE('*',LENGTH(FIELDVALUE(InputRoot.XMLNSC.ns: comprarContenidoTarjetaRequest.ns:numero_tarjeta))); |
Unless you want underscores, dots and other special charecters left in place, of course. |
|
Back to top |
|
 |
fpg8 |
Posted: Mon Apr 09, 2012 7:50 am Post subject: |
|
|
Novice
Joined: 26 Mar 2012 Posts: 15
|
Esa wrote: |
Maybe something like this would do:
Code: |
SET numero_tarjeta_for = REPLICATE('*',LENGTH(FIELDVALUE(InputRoot.XMLNSC.ns: comprarContenidoTarjetaRequest.ns:numero_tarjeta))); |
Unless you want underscores, dots and other special charecters left in place, of course. |
Thank you very much for the reply. I will try.
For now, I did work like this:
SET numero_tarjeta_for = InputRoot.XMLNSC.ns:comprarContenidoTarjetaRequest.ns:numero_tarjeta;
SET numero_tarjeta = '';
SET i = 1;
IF (numero_tarjeta_for IS NOT NULL) THEN
X : WHILE i <= Length(numero_tarjeta_for) DO
SET numero_tarjeta = numero_tarjeta || '*';
SET i = i + 1;
END WHILE X;
END IF; |
|
Back to top |
|
 |
fpg8 |
Posted: Mon Apr 09, 2012 8:03 am Post subject: |
|
|
Novice
Joined: 26 Mar 2012 Posts: 15
|
Esa,
It worked, Thank you for provide me ANSWERS. |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 09, 2012 9:19 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fpg8 wrote: |
For now, I did work like this:
SET numero_tarjeta_for = InputRoot.XMLNSC.ns:comprarContenidoTarjetaRequest.ns:numero_tarjeta;
SET numero_tarjeta = '';
SET i = 1;
IF (numero_tarjeta_for IS NOT NULL) THEN
X : WHILE i <= Length(numero_tarjeta_for) DO
SET numero_tarjeta = numero_tarjeta || '*';
SET i = i + 1;
END WHILE X;
END IF; |
Whatever works for you.
TRANSLATE would also do this. So would REPLACE as you had it with the correct string. So would something like:
Code: |
SET numero_tarjeta = REPLICATE('*',LENGTH(COALESCE(InputRoot.XMLNSC.ns:comprarContenidoTarjetaRequest.ns:numero_tarjeta,'')) |
Many possible answers. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Apr 09, 2012 8:11 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Seemed very complicate when something simple would have made it too like
Code: |
SET maskedpart = replicate('*',12);
SET lastdigits = right(cardnumber,4);
SET fieldvalue = maskedpart || lastdigits; |
Well, there's a million ways to ....
Note that no animals whatsoever were harmed in this post  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqsiuser |
Posted: Mon Apr 09, 2012 10:20 pm Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
fjb_saper wrote: |
Well, there's a million ways to .... |
@OP: First challenge: Find something (that works)... then (second challenge): Make it (probably find something else ) work best for you (often performance is a requirement).
fjb_saper wrote: |
Note that no animals whatsoever were harmed in this post  |
With some experience you will then just do things in a certain way. Poor cat btw. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
Vitor |
Posted: Tue Apr 10, 2012 4:40 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fjb_saper wrote: |
Well, there's a million ways to .... |
There are.
fjb_saper wrote: |
Note that no animals whatsoever were harmed in this post  |
Speak for yourself.....  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|