Page 1 of 1
Check only ALPHANUMERIC characters
Posted: Wed Sep 30, 2015 2:56 am
by karthi_gana
All,
I have to check whether a string contains only alpha numeric characters.
I used ALPHA() Function, but it is not giving the expected result set.
Input file has
"STREAM GSDW NSC D" - Expected Result Set is OK
"STREAM GSDW1 NSC D" - Expected Result Set is FAILED.
As It contains "1".
ALPHA() or ISVALID(String,DSLInk1.columnname) functions are not returning the expected result set.
Note: The data type of the column is varchar(50)
Inputs are welcome!
Posted: Wed Sep 30, 2015 5:44 am
by rkashyap
"Alpha" function checks if the given string contains only alphabetic characters. In order to check for alphanumeric characters, use
AlNum function.
Posted: Wed Sep 30, 2015 6:06 am
by qt_ky
It's been a while but I think those functions are strict in that if the string contains whitespace then they will return false. Is that correct? Spaces are not alphabetic nor numeric.
Posted: Wed Sep 30, 2015 6:19 am
by rkashyap
I believe that AlNum can handle spaces. Excerpt from example for
AlNum function.
Examples. If mylink.mystring1 contains the string "OED_75_9*E", then the following function would return the value 0 (false).
AlNum(mylink.mystring1)
If mylink.mystring2 contains the string "12 red roses", then the following function would return the value 1 (true).
AlNum(mylink.mystring2)
Posted: Wed Sep 30, 2015 10:39 am
by qt_ky
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
Do not trust the documentation.
A quick test is in order. Here are a few input strings and function results from version 11.3.1.2.
Code: Select all
AlNum:1 Alpha:1 STRING:Alpha
AlNum:0 Alpha:0 STRING:Alpha with spaces
AlNum:0 Alpha:0 STRING:Alpha_with_underscores
AlNum:1 Alpha:0 STRING:AlphaNumeric123
AlNum:0 Alpha:0 STRING:Alpha Numeric 123 with spaces
AlNum:0 Alpha:0 STRING:Alpha_Numeric_123_with_underscores
AlNum:1 Alpha:0 STRING:123
AlNum:0 Alpha:0 STRING:1 2 3
AlNum:0 Alpha:0 STRING:1_2_3
To answer the original question/expectation, you would first have to remove whitespace then test using Alpha() or AlNum() depending on the desired results.
Posted: Wed Sep 30, 2015 10:54 am
by eostic
Nice test grid! This post ought to be a sticky. THANKS! ; )
Posted: Wed Sep 30, 2015 11:41 am
by chulett
You can always save it as a Favorite.
Posted: Wed Sep 30, 2015 2:38 pm
by eostic
Sounds like a good idea.....how does it work? Never used it. I see the "Favorites" link at the top, but don't see how to target a particular post.
Ernie
Posted: Wed Sep 30, 2015 2:59 pm
by chulett
The option to Add to Favorites is on the far right-hand side of the page, both at the very top and bottom of the page/screen. Clicking it will put a link to the topic in your Favorites so you can get back to it easily.
Posted: Wed Sep 30, 2015 8:11 pm
by eostic
Cool. Thanks. Never noticed it.
Posted: Thu Oct 01, 2015 4:05 am
by karthi_gana
I removed the whitespaces by using stripwhitespace function and then applied ALPHA..But the output of ALPHA is 0 instaed of 1. why?
"STREAM GSDW nsc D"
I used the above string only in my file.
Posted: Thu Oct 01, 2015 6:22 am
by qt_ky
If you did a derivation like Alpha(StripWhiteSpace(Col)) and Col=a b c then it should return 1 for true. If the double quotes are actually part of the string as in Col="a b c" the it should return 0 for false. Check the quote character value you have set when reading the file.