Announcement

Collapse
No announcement yet.

PB/DOS: Compare 2 strings which may contain DOS-Wildcards * and ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB/DOS: Compare 2 strings which may contain DOS-Wildcards * and ?

    Code:
    '
    ' Unit.............COMPDW1.PBL
    ' Zweck............Uppercase-Stringvergleich mit MSDOS-Wildcards * und ?
    ' Version..........1.00
    ' Stand............11.05.95
    ' Sprache..........PowerBASIC 3.0
    ' Autor............M.Hoffmann
    '
    
    $com      0
    $compile  unit
    $cpu      80386
    $debug    map-,pbdebug-,path-,unit-
    $dim      all
    $error    bounds-,numeric-,overflow-,stack-,param-
    $event    off
    $float    emulate
    $lib      com-,lpt-,cga-,ega-,vga-,fullfloat-,iprint-
    $optimize size
    $option   cntlbreak-,gosub-,signed-
    $static
    
    function CompDW (Strg1 AS STRING, Strg2 AS STRING) public as integer
       ' Compare/DOS Wildcards
       ' Vergleicht zwei Strings unter Berücksichtigung der Wildcards
       ' * und ? wie bei MS-DOS. Die Argumente werden in Uppercase umgewandelt.
       ' Ergebnisse:
       '  1 = Match
       '  0 = Kein Match
       dim a1 as local integer ' ASCII-Code eines Zeichens aus s1
       dim a2 as local integer ' ASCII-Code eines Zeichens aus S2
       dim s1 as local string  ' Strg1 in UPPERCASE
       dim s2 as local string  ' Strg2 in UPPERCASE
       dim l  as local integer ' Länge des längeren Strings
       dim i  as local integer ' Zähler
       CompDW = 0
       s1 = ucase$(Strg1) : s2 = ucase$(Strg2) : l = max%(len(s1),len(s2))
       for i=1 to l
          a1 = ASCII(mid$(s1,i,1))
          a2 = ASCII(mid$(s2,i,1))
          if a1 = 63 or a2 = 63 then
             iterate for
          elseif a1 = 42 or a2 = 42 then
             exit for
          elseif a1 <> a2 then
             exit function
          end if
       next
       CompDW = 1
    end function
    ------------------
Working...
X