About Don Schullian Expertise I`ve worked in BASIC since the Commodore days and maintain a web site part of which is devoted to helping others with thier problems. I`m proficient in all versions of PowerBASIC but cross over to QuickBASIC and Qbasic frequently.
Question Hi Don,
I am working in QB 4.5 and trying to manipulate a string that represents sample information
Below is an example string
"=e804f030,28-30cm,0.2987in,s2008256,ct2008300,15.317g,c2008270—"
I would like to remove all non alpha numeric characters except decimal, dash, and comma and then put each part of the string separated by a comma into its own string for expert
the above string would be transformed into the following:
Once the information was divided up, would it then be possible to remove the alpha characters on some of the individual strings? For example, I'd like to keep the alpha information in the first two new strings but remove it from the rest e.g.,
s7$=c2008270 becomes 2008270
Thanks in advance.
Best regards,
Tim
Answer Hi Tim,
The code below seems to work. I wrote routines like these decades ago but couldn't find the originals. So..... I think these work. The SUB ParseString will only work correctly when the Sep$ is one character in length.
BTW, I don't have a DOS compiler loaded any more so you may have to fuss with the code a bit to get it to work in QB as I couldn't test it directly.
FUNCTION fRetain$ ( InString$, Keep$ )
FOR P% = 1 TO LEN(InString$)
C$ = MID$(InString$,P%,1)
IF INSTR(Keep$,C$) > 0 THEN
OutString$ = OutString$ + C$
END IF
NEXT
fRetain$ = OutString$
END FUNCTION
FUNCTION fParseCount% ( InString$, Sep$ )
L% = LEN(Sep$)
P% = 1-L%
DO
C% = C% + 1
P% = P% + L%
P% = INSTR(P%,InString$, Sep$)
LOOP UNTIL P% = 0
fParseCount% = C%
END FUNCTION
SUB ParseString ( InString$, Sep$, Arr$() )
Last% = UBOUND(Arr$())
FOR C% = 1 TO Last%
P1% = P1% + 1
P2% = INSTR(P1%,InString$,Sep$)
IF P2% = 0 THEN P2% = LEN(InString$) + 1
Arr$(C%) = MID$(InString$,P1%,P2%-P1%)
P1% = P2%
NEXT