SRTING FUNCTION

Dear all,

Iam creating a functions in form .When the user enter the details as follows .

sam :‘axy2345mn’

result:

command: the result should be 2345 i.e

STR shoul return only integer value.

Which STRING function can i use please help me out.

Thanks in advance!

R.Ramanathan

Example

CAL Global/local:
Inputtext Text

ReturnInteger Integer

Code:

Inputtext:=DELCHR(‘am1234sc’,’=’,‘abcdefghijklmnopqrstuxyzABCDEFGHIJKLMNOPQRSTUXYZ’);
EVALUATE(returnInteger,Inputtext);
MESSAGE(’%1’,returnInteger);

That one will work with the characters mentioned. If your string looks like below, you have to change your definition. Or use a code like this:

(txString = Text, coNumber = Code, i = Integer)

txString := ‘#asdf-64’;

FOR i := 1 TO STRLEN(txString) DO
IF (COPYSTR(txString, i, 1) >= ‘0’) AND (COPYSTR(txString, i, 1) <= ‘9’) THEN
coNumber := coNumber + COPYSTR(txString, i, 1);

//Now txString is intact; coNumber is ‘64’


REM: You cannot use syntax “coNumber += COPYSTR(txString, i, 1);” as this does not work on Code.

Here’s my implementation, which in a way is kind of similar to LHI, since I also use a lookup string

but instead of looking at characters to exclude, I’ve opted to for a lookup string that include only the characters to allow (since there are only 10 of them) and since there aretoo many characters to exclude, beside the Alphabets (lower & upper caser), they can enter stuffs lile _ % + - ! & ( )

I guess the solution above should be reliable & robust enough, and is also flexible , if you wanted to add characters to allow in your input,just add them in the lookup string (NumbersOnlyLOC), and the rest of the code will remaint the same

// GetNumbersOnly

GetNumbersOnly(NumbersStringPAR : Code[1024]) : Code[1024]

NumbersOnlyLOC := ‘01234567890’; // Lookupstring of characters to allow

CleanedString := ‘’;

FOR i := 1 TO STRLEN (NumbersStringPAR ) DO
BEGIN
CurrCharLOC := COPYSTR(NumbersStringPAR, i, 1);
IF STRPOS(NumbersOnlyLOC, CurrCharLOC ) <> 0 THEN
CleanedString := CleanedString + CurrCharLOC;
END;

EXIT ( CleanedString );