Page 1 of 1

Trim issues

Posted: Sun Apr 15, 2007 8:35 pm
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

Posted: Sun Apr 15, 2007 9:23 pm
by chulett
Why the 'trim' function? Why not something more appropriate to the task?

Posted: Sun Apr 15, 2007 9:30 pm
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.

Posted: Sun Apr 15, 2007 11:38 pm
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

Posted: Sun Apr 15, 2007 11:46 pm
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?

Posted: Sun Apr 15, 2007 11:55 pm
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.

Posted: Sun Apr 15, 2007 11:57 pm
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 "".

Posted: Sun Apr 15, 2007 11:59 pm
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().

Re: Trim issues

Posted: Mon Apr 16, 2007 12:26 am
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]

Posted: Mon Apr 16, 2007 6:47 am
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

Posted: Mon Apr 16, 2007 7:09 am
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.

Posted: Mon Apr 16, 2007 3:16 pm
by ray.wurlod
Tip: You can treat the single character as an integer to get its ASCII code.

Question: what if NLS is enabled?

Posted: Mon Apr 16, 2007 3:32 pm
by DSguru2B
ray.wurlod wrote:
Question: what if NLS is enabled?
Good question, will have to try that out some time.