home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 101.img / QB45-1.ZIP / STRTONUM.BAS < prev    next >
BASIC Source File  |  1987-09-23  |  1KB  |  35 lines

  1. DECLARE FUNCTION Filter$ (Txt$, FilterString$)
  2.  
  3. ' Input a line:
  4. LINE INPUT "Enter a number with commas: ", A$
  5.  
  6. ' Look for only valid numeric characters (0123456789.-) in the
  7. ' input string:
  8. CleanNum$ = Filter$(A$, "0123456789.-")
  9.  
  10. ' Convert the string to a number:
  11. PRINT "The number's value = "; VAL(CleanNum$)
  12. END
  13. '
  14. ' ========================== FILTER ==========================
  15. '         Takes unwanted characters out of a string by
  16. '        comparing them with a filter string containing
  17. '             only acceptable numeric characters
  18. ' ============================================================
  19. '
  20. FUNCTION Filter$ (Txt$, FilterString$) STATIC
  21.    Temp$ = ""
  22.    TxtLength = LEN(Txt$)
  23.  
  24.    FOR I = 1 TO TxtLength     ' Isolate each character in
  25.       C$ = MID$(Txt$, I, 1)   ' the string.
  26.  
  27.       ' If the character is in the filter string, save it:
  28.       IF INSTR(FilterString$, C$) <> 0 THEN
  29.          Temp$ = Temp$ + C$
  30.       END IF
  31.    NEXT I
  32.  
  33.    Filter$ = Temp$
  34. END FUNCTION
  35.