Page 1 of 1

Can We calculate the no. of Alpha Char. in a string

Posted: Wed Dec 13, 2006 1:09 am
by ajmore
Hi All :D ,

I have to do a validation on a Varchar field as follows....

1) First Char must be Alpha---i got this using function Alpha(Left(inxfmLoadData1.DFSNAM,1)) = 1

2) Valid char.. r Alphabets,Blanks,Hypens and Apostrophes...

3) Blanks,Hypens and Apostrophes must not be adjacent

Can anybody Help me in this issue..

:idea: Also Please provide me the method to Calculate the no. of Alphabets in a String in Transformer i will then move fwd with some logic...

Thanks in Advance

Posted: Wed Dec 13, 2006 1:25 am
by ray.wurlod
You don't need to count them to validate that only the appropriate types are in the string.

Alpha() will work on the entire string, returning 1 if every character in the string is alphabetic.

The easiest way to test for a set of valid characters is to convert them all to "" then test the length of the remainder.

Code: Select all

Len(Convert("ABCDEFGHIJKLMNOPQRSTUVWXYZ -'abcdefghijklmnopqrstuvwxyz", "", InLink.TheString)) = 0
This expression is true for a valid string and false for a string containing any invalid character.

Re: Can We calculate the no. of Alpha Char. in a string

Posted: Wed Dec 13, 2006 1:30 am
by ajith
ajmore wrote:Hi All :D ,

I have to do a validation on a Varchar field as follows....

1) First Char must be Alpha---i got this using function Alpha(Left(inxfmLoadData1.DFSNAM,1)) = 1

2) Valid char.. r Alphabets,Blanks,Hypens and Apostrophes...

3) Blanks,Hypens and Apostrophes must not be adjacent

Can anybody Help me in this issue..

:idea: Also Please provide me the method to Calculate the no. of Alphabets in a String in Transformer i will then move fwd with some logic...

Thanks in Advance
I think this can be better done via scripting rather than Datastage. You can use anything that supports regular expressions and do this.

All of your requirements are related to string manipulation, and there are no extensive support for string manipulation in datastage other than the basic ones. So I think It would better be done outside datastage than inside it. It is only a suggestion

Thanks,
Ajith

Posted: Wed Dec 13, 2006 8:04 am
by chulett
Actually, I'd say the support for string manipulation in DataStage is very extensive. 'Better' is a relative word, so perhaps in some instances in some shops there are 'better' ways to do it, but I prefer to stay in the tool if at all possible... and I don't recall the last time that wasn't possible. :wink:

Posted: Wed Dec 13, 2006 8:52 am
by ajith
chulett wrote:Actually, I'd say the support for string manipulation in DataStage is very extensive. 'Better' is a relative word, so perhaps in some instances in some shops there are 'better' ways to do it, but I prefer to stay in the tool if at all possible... and I don't recall the last time that wasn't possible. :wink:
:oops:

my post could have been phrased better(relative :roll: ) and don't make me an anti-Datastage terrorist :cry: :cry:

Posted: Wed Dec 13, 2006 9:32 am
by chulett
:lol: No worries. I'll call the FBI back and tell them "never mind".

Posted: Wed Dec 13, 2006 3:07 pm
by ray.wurlod
My earlier post did not address your third requirement, that legal non-alphabetic characters must not be adjacent.

This one is not possible using out-of-the-box functions, since you need to loop through each adjacent pair of characters. You will need to create either a parallel routine (external C++ code) or a BuildOp stage (internal C++ code) to achieve this result.