Author |
Message
|
neeha_kashyap120 |
Posted: Wed Dec 23, 2009 7:00 am Post subject: Passing only numeric values |
|
|
 Apprentice
Joined: 05 Mar 2009 Posts: 31
|
Hi
I am doing a XML --> XML transformation. One of the source fields can have a value that is either numeric or a combination of numeric and character values. I need to pass only the numeric values and remove the character values.
The characters can occur at any position and in upper or lower case.
Like if the source value is a123bc456, the target value should be 123456.
Can someone help me as to how to find and remove the character values.
Thanks _________________ Neeharika Kashyap
IBM Certified System Administrator - WebSphere MQ V6.0
Trying to be IBM Certified System Administrator - WebSphere Message Broker V6.1 and IBM Certified Solution Developer - WebSphere Message Broker V6.1 |
|
Back to top |
|
 |
amiivas |
Posted: Wed Dec 23, 2009 9:07 am Post subject: |
|
|
Apprentice
Joined: 14 Oct 2007 Posts: 44 Location: Texas, USA
|
you can write a function for parsing that string and only taking those characters which are in the range of numeric ascii values. This can easily be done in Java compute node using regex function but for esql, you need to call java function or hardcode the logic. I know this is a work around solution as well as a performance degradation, but take it as a last choice.  _________________ IBM WebSphere Certified Solution Developer |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Dec 23, 2009 9:19 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
amiivas wrote: |
you can write a function for parsing that string and only taking those characters which are in the range of numeric ascii values. This can easily be done in Java compute node using regex function but for esql, you need to call java function or hardcode the logic. I know this is a work around solution as well as a performance degradation, but take it as a last choice.  |
Of course, esql provides several character replacement functions that can be used directly to do this as well, even if not strictly a "regex" function. The TRANSLATE function is a natural choice here. |
|
Back to top |
|
 |
cool_ziv |
Posted: Wed Dec 23, 2009 9:28 am Post subject: |
|
|
Newbie
Joined: 24 Nov 2009 Posts: 8
|
|
Back to top |
|
 |
cool_ziv |
Posted: Wed Dec 23, 2009 9:37 am Post subject: |
|
|
Newbie
Joined: 24 Nov 2009 Posts: 8
|
This should do the trick.
TRANSLATE(StringVariable,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','');
or
TRANSLATE(LCASE(StringVariable),'abcdefghijklmnopqrstuvwxyz','');
I used LCASE just to reduce the number of searchstringexpressions. |
|
Back to top |
|
 |
neeha_kashyap120 |
Posted: Wed Dec 23, 2009 11:04 am Post subject: |
|
|
 Apprentice
Joined: 05 Mar 2009 Posts: 31
|
Thanks a lot guys.
I did try with TRANSLATE earlier but I was coding as TRANSLATE(Value,[a-z],'') which was erroring out. I will try this and see if that works.
Neeha _________________ Neeharika Kashyap
IBM Certified System Administrator - WebSphere MQ V6.0
Trying to be IBM Certified System Administrator - WebSphere Message Broker V6.1 and IBM Certified Solution Developer - WebSphere Message Broker V6.1 |
|
Back to top |
|
 |
amiivas |
Posted: Wed Dec 23, 2009 11:23 am Post subject: |
|
|
Apprentice
Joined: 14 Oct 2007 Posts: 44 Location: Texas, USA
|
cool_ziv wrote: |
This should do the trick.
TRANSLATE(StringVariable,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','');
or
TRANSLATE(LCASE(StringVariable),'abcdefghijklmnopqrstuvwxyz','');
I used LCASE just to reduce the number of searchstringexpressions. |
gr8 that will definitely work, nowadays I am working more with Java hence more java oriented...  _________________ IBM WebSphere Certified Solution Developer |
|
Back to top |
|
 |
neeha_kashyap120 |
Posted: Tue Jan 05, 2010 12:58 pm Post subject: Checking for all non-numeric characters and removing them |
|
|
 Apprentice
Joined: 05 Mar 2009 Posts: 31
|
Hi
Thanks to everyone's input in my previous post I was able to remove all teh alphabetic values from a source field. But is there a way to remove any character thats not a number from 0-9. Which may include special characters. Or maybe some way to pass only numbers 0-9.
Thanks in advance _________________ Neeharika Kashyap
IBM Certified System Administrator - WebSphere MQ V6.0
Trying to be IBM Certified System Administrator - WebSphere Message Broker V6.1 and IBM Certified Solution Developer - WebSphere Message Broker V6.1 |
|
Back to top |
|
 |
ggriffith |
Posted: Fri Jan 08, 2010 8:37 am Post subject: |
|
|
 Acolyte
Joined: 17 Oct 2007 Posts: 67
|
DECLARE inp CHARACTER InputRoot.XMLNSC.Data.str1;
DECLARE temp CHARACTER;
DECLARE outp CHARACTER '';
DECLARE i INTEGER 1;
DECLARE j INTEGER length(inp);
WHILE i <= j DO
SET temp = SUBSTRING(inp FROM i FOR 1);
IF LENGTH(TRANSLATE(temp,'0123456789','')) = 0 THEN
SET outp = outp || temp;
END IF;
SET i = i + 1;
END WHILE;
SET OutputRoot.XMLNSC.Data.str1 = outp; |
|
Back to top |
|
 |
|