Trim issues

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
xinhuang66
Participant
Posts: 161
Joined: Wed Aug 02, 2006 4:30 am

Trim issues

Post by xinhuang66 »

Somebody can tell me how to get numbers and letters from such a string by trim function.

KBN12390 -> to get KBN and 12390
234BN -> to get 234 and BN.

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why the 'trim' function? Why not something more appropriate to the task?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could create your own parallel routine. Make sure it handles letters of both lower case and upper case if this is what your business rules require.

For small volumes you could use a BASIC Transformer stage and use the DIGITS and LETTERS Transforms.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
xinhuang66
Participant
Posts: 161
Joined: Wed Aug 02, 2006 4:30 am

Post by xinhuang66 »

I don't want to go to Routine. And I use

trim(convert(field1, "ABCDEFG...Z","")) to get rid of letters.

It works in my case, does it cause any potential problems
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The convert, not the trim, is removing the letters for you. Does it cause any potential problems? You'd have to tell us - it only removes upper-case letters from the string, is that enough to solve your particular problem?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The syntax (argument order) in your Convert() function is incorrect, and this approach is not general - as Craig notes, it removes only upper case letters.
Trim() achieves nothing here.

Code: Select all

Convert("ABCDEFGHIJKLMONPQRSTUVWXYZ", "", Upcase(InLink.TheString))
is more general, but removes only alphabetic characters.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
htrisakti3
Charter Member
Charter Member
Posts: 36
Joined: Thu Jun 10, 2004 11:22 pm

Post by htrisakti3 »

Looking at your examples, I'd approach it:
a. get numeric part from string
use Iconv MCN to get numeric part

b. get string part..
use Ereplace, with arguments to replace numeric part above with "".
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Have you written a parallel version of the Iconv() or Oconv() function that you can share with us?

If you have, an "MCA" conversion will return just the letters - no need for Ereplace().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sudeepmantri
Participant
Posts: 54
Joined: Wed Oct 25, 2006 11:07 pm
Location: Hyderabad

Re: Trim issues

Post by sudeepmantri »

Why Use a trim for this, U can very well use left and right functions provided in the transaformer.

KBN12390 -> to get KBN and 12390
234BN -> to get 234 and BN.

Thanks[/quote]
xinhuang66
Participant
Posts: 161
Joined: Wed Aug 02, 2006 4:30 am

Post by xinhuang66 »

chulett wrote:The convert, not the trim, is removing the letters for you. Does it cause any potential problems? You'd have to tell us - it only removes upper-case letters from the string, is that enough to solve your particular problem?
It works in my case actually.

And also I use Convert(field, "1234567890","") to remove number as well. and it works.

Thanks

By the way, I am interested in the routine to trim Characters or numbers, anybody can post a sample code here.

Thanks
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

How good are your C skills? Writing a C function that will remove letters/digits is not hard. You will have to read the string, one character at a time, assign it to an integer variable which will store the character's ascii code. You can constraint ascii codes to integers and alphabets.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Tip: You can treat the single character as an integer to get its ASCII code.

Question: what if NLS is enabled?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

ray.wurlod wrote:
Question: what if NLS is enabled?
Good question, will have to try that out some time.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply