home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / qb_sub / strip.sub < prev    next >
Encoding:
Text File  |  1987-07-14  |  4.6 KB  |  178 lines

  1. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. '%  (C) 1987 HUMBLEWARE Custom Programming    Author: Lawrence A. Westhaver  %
  3. '%        247 Paul Martin Drive,  Baltimore MD  21227  (301) 799-1975        %
  4. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. '%                                                                           %
  6. '%     FILENAME: STRIP.SUB                       LAST UPDATE: 05-24-1987     %
  7. '%                                                                           %
  8. '%  DESCRIPTION: Four routines that strip spaces (ASCII 32) from an input    %
  9. '%               string.                                                     %
  10. '%                                                                           %
  11. '%         CALL: CALL STRIPxxx(IN$,OUT$)                                     %
  12. '%                                                                           %
  13. '%                 STRIPALL: Strips all spaces from a string regardless of   %
  14. '%                           position.                                       %
  15. '%                                                                           %
  16. '%                 STRIPLR:  Strips spaces from the left and right sides     %
  17. '%                           of a string.                                    %
  18. '%                                                                           %
  19. '%                 STRIPL:   Strips spaces from the left side of a string.   %
  20. '%                                                                           %
  21. '%                 STRIPR:   Strips spaces from the right side of a string.  %
  22. '%                                                                           %
  23. '%       INPUTS: IN$  = Input string.                                        %
  24. '%                                                                           %
  25. '%      OUTPUTS: OUT$ = Copy of input string with spaces stripped.           %
  26. '%                                                                           %
  27. '%         NOTE: These routines do not alter the original string specified   %
  28. '%               in IN$. They return a copy of the original string in OUT$   %
  29. '%               with spaces stripped.                                       %
  30. '%                                                                           %
  31. '%               If you want the original string altered, then call the      %
  32. '%               needed routine like this:                                   %
  33. '%                                                                           %
  34. '%                             CALL STRIPxxx(IN$,IN$)                        %
  35. '%                                                                           %
  36. '%               This will cause the copy of the original string to be       %
  37. '%               assigned to the original.                                   %
  38. '%                                                                           %
  39. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40.  
  41.  
  42. SUB STRIPALL(IN$,OUT$) Static
  43.  
  44.  
  45. 'check if string has only spaces
  46.  
  47.     IF IN$=STRING$(LEN(IN$)," ") THEN
  48.       OUT$=""
  49.       EXIT SUB
  50.     END IF
  51.  
  52.  
  53. 'check for null string
  54.  
  55.      IF IN$="" THEN
  56.        OUT$=""
  57.        EXIT SUB
  58.      END IF
  59.  
  60.  
  61. 'strip out spaces
  62.  
  63.     TEMP$=""
  64.     FOR LEWP%=1 TO LEN(IN$)
  65.       IF MID$(IN$,LEWP%,1)<>" " THEN TEMP$=TEMP$+MID$(IN$,LEWP%,1)
  66.     NEXT LEWP%
  67.     OUT$=TEMP$
  68.  
  69.  
  70. END SUB 'stripall
  71.  
  72.  
  73.  
  74. SUB STRIPLR(IN$,OUT$) Static
  75.  
  76.  
  77. 'check if string has only spaces
  78.  
  79.     IF IN$=STRING$(LEN(IN$)," ") THEN
  80.       OUT$=""
  81.       EXIT SUB
  82.     END IF
  83.  
  84.  
  85. 'check for null string
  86.  
  87.     IF IN$="" THEN
  88.       OUT$=""
  89.       EXIT SUB
  90.     END IF
  91.  
  92.  
  93. 'call strip left
  94.  
  95.     CALL STRIPL(IN$,OUT$)
  96.  
  97.  
  98. 'call strip right
  99.  
  100.     CALL STRIPR(OUT$,OUT$)
  101.  
  102.  
  103. END SUB 'striplr
  104.  
  105.  
  106.  
  107. SUB STRIPL(IN$,OUT$) Static
  108.  
  109.  
  110. 'check if string has only spaces
  111.  
  112.     IF IN$=STRING$(LEN(IN$)," ") THEN
  113.       OUT$=""
  114.       EXIT SUB
  115.     END IF
  116.  
  117.  
  118. 'check for null string
  119.  
  120.      IF IN$="" THEN
  121.        OUT$=""
  122.        EXIT SUB
  123.      END IF
  124.  
  125.  
  126. 'strip left hand spaces
  127.  
  128.     POINTER%=1
  129.  
  130. STRIPL:
  131.  
  132.     IF MID$(IN$,POINTER%,1)=" " THEN
  133.       POINTER%=POINTER%+1
  134.       GOTO STRIPL
  135.     END IF
  136.  
  137.     OUT$=MID$(IN$,POINTER%)
  138.  
  139.  
  140. END SUB 'stripl
  141.  
  142.  
  143.  
  144. SUB STRIPR(IN$,OUT$) Static
  145.  
  146.  
  147. 'check if string has only spaces
  148.  
  149.     IF IN$=STRING$(LEN(IN$)," ") THEN
  150.       OUT$=""
  151.       EXIT SUB
  152.     END IF
  153.  
  154.  
  155. 'check for null string
  156.  
  157.     IF IN$="" THEN
  158.       OUT$=""
  159.       EXIT SUB
  160.     END IF
  161.  
  162.  
  163. 'strip right hand spaces
  164.  
  165.     POINTER%=LEN(IN$)
  166.  
  167. STRIPR:
  168.  
  169.     IF MID$(IN$,POINTER%,1)=" " THEN
  170.       POINTER%=POINTER%-1
  171.       GOTO STRIPR
  172.     END IF
  173.  
  174.     OUT$=LEFT$(IN$,POINTER%)
  175.  
  176.  
  177. END SUB 'stripr
  178.