[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Extract only numbers of a string

Status
Not open for further replies.
D

David Abdala

Guest
I don't know whats the meaning of "simple" and "fastest" for you.. Usually numbers in a string are at the beginning of it, or after a space, so you can simplify the search by using ENTRY: def var mchEntry as char no-undo. def var minLE as integer no-undo def var minInd as integer no-undo def var minPos as integer no-undo. minLE = NUM-ENTRIES(ipchString,' '). DO minInd = 1 TO minLE: mchEntry = ENTRY(minInd,ipchString,' '). IF LOOKUP(SUBSTRING(mchEntry,1,1),'0,1,2,3,4,5,6,7,8,9') EQ 0 THEN NEXT. minPos = 2. DO WHILE minPos LT LENGTH(mchEntry) AND LOOKUP(SUBSTRING(mchEntry,minPos,1),'0,1,2,3,4,5,6,7,8,9') GT 0: minPos = minPos + 1. END. RETURN SUBSTRING(mchEntry,1,minPos). /* your number, assuming you just want the first number in the string*/ END. RETURN ''. /* no numbers in the string */ It is "simple" to understand, and the "fastest" to write and use...

Continue reading...
 
Status
Not open for further replies.
Top