Consultor Eletrônico



Kbase P135379: Sample code for parsing an input string and returning a formatted phone number
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   23/09/2008
Status: Unverified

GOAL:

Sample code for parsing an input string and returning a formatted phone number

FACT(s) (Environment):

All Supported Operating Systems
Progress/OpenEdge Versions

FIX:

FUNCTION isInteger RETURNS LOGICAL ( INPUT pcString AS CHARACTER ):
DEFINE VARIABLE iInteger AS INTEGER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE lInteger AS LOGICAL NO-UNDO.

/* Read string one character at a time and test to see if it's an integer */
DO iCounter = 1 TO LENGTH(pcString):
iInteger = INTEGER(SUBSTRING(pcString,iCounter,1)) NO-ERROR.
lInteger = NOT (ERROR-STATUS:NUM-MESSAGES GT 0).
IF NOT lInteger THEN
LEAVE.
END.

RETURN lInteger.
END FUNCTION.

FUNCTION convertToPhoneNumber RETURNS CHARACTER
( INPUT pcInput AS CHARACTER ):
DEFINE VARIABLE cString AS CHARACTER NO-UNDO FORMAT "x(30)".

IF isInteger(pcInput) THEN
cString = STRING(pcInput,"(999)999-9999 x(4)").
ELSE
cString = pcInput + " - Is not a valid phone number".

RETURN cString.
END FUNCTION.

MESSAGE convertToPhoneNumber("erfg34fer") SKIP
convertToPhoneNumber("54555590889888")
VIEW-AS ALERT-BOX INFO BUTTONS OK.