home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
101.img
/
QB45-1.ZIP
/
STRTONUM.BAS
< prev
next >
Wrap
BASIC Source File
|
1987-09-23
|
1KB
|
35 lines
DECLARE FUNCTION Filter$ (Txt$, FilterString$)
' Input a line:
LINE INPUT "Enter a number with commas: ", A$
' Look for only valid numeric characters (0123456789.-) in the
' input string:
CleanNum$ = Filter$(A$, "0123456789.-")
' Convert the string to a number:
PRINT "The number's value = "; VAL(CleanNum$)
END
'
' ========================== FILTER ==========================
' Takes unwanted characters out of a string by
' comparing them with a filter string containing
' only acceptable numeric characters
' ============================================================
'
FUNCTION Filter$ (Txt$, FilterString$) STATIC
Temp$ = ""
TxtLength = LEN(Txt$)
FOR I = 1 TO TxtLength ' Isolate each character in
C$ = MID$(Txt$, I, 1) ' the string.
' If the character is in the filter string, save it:
IF INSTR(FilterString$, C$) <> 0 THEN
Temp$ = Temp$ + C$
END IF
NEXT I
Filter$ = Temp$
END FUNCTION