Author |
Message
|
kevinmark99 |
Posted: Wed May 22, 2013 5:56 am Post subject: Esql : read a string and findout if it has an integer inside |
|
|
Newbie
Joined: 29 Mar 2013 Posts: 8
|
I am a newbie in ESQL,
I am trying to findout if its possible to findout if
kevinmark99@yahoo.com has a number in it ; i can split and extract out "99" as String, but i need to determine if its a string or int can anyone help me out on this? |
|
Back to top |
|
 |
Vitor |
Posted: Wed May 22, 2013 6:10 am Post subject: Re: Esql : read a string and findout if it has an integer in |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
kevinmark99 wrote: |
i can split and extract out "99" as String, but i need to determine if its a string or int can anyone help me out on this? |
Cast the extracted string to an integer with a nonsensical default value, and then check for the nonsensical value. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqsiuser |
Posted: Thu May 23, 2013 1:07 am Post subject: Re: Esql : read a string and findout if it has an integer in |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Vitor wrote: |
Cast the extracted string to an integer |
Either you cast to INT, or (if you want to avoid the exception) use a utility function:
Code: |
containsCharsOnly( extractedString, '0123456789' ); |
Code: |
CREATE PROCEDURE containsCharsOnly ( IN string CHAR, IN chars CHAR ) RETURNS BOOLEAN
BEGIN
DECLARE length1 INT LENGTH( string );
DECLARE i INT 1;
WHILE i <= length1 DO
DECLARE char1 CHAR SUBSTRING( string FROM i FOR 1 );
IF POSITION( char1 IN chars ) = 0 THEN -- Found something else than the chars in 'chars'
RETURN FALSE;
END IF;
SET i = i + 1;
END WHILE;
RETURN TRUE;
END; |
_________________ Just use REFERENCEs |
|
Back to top |
|
 |
mqjeff |
Posted: Thu May 23, 2013 4:03 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Delete all characters that are 0-9.
If the string is not empty, it's not an integer. |
|
Back to top |
|
 |
mqsiuser |
Posted: Thu May 23, 2013 5:40 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
mqjeff wrote: |
Delete all characters that are 0-9.
If the string is not empty, it's not an integer. |
There are many ways... a... skinny cat... may go.
But one may be faster and the other slower. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
|