Search 1/2

 BBS: Inland Empire Archive
Date: 01-17-93 (01:17)             Number: 339
From: DIK COATES                   Refer#: NONE
  To: TOM CARROLL                   Recvd: NO  
Subj: Search 1/2                     Conf: (2) Quik_Bas
>>>> QUOTING Dik Coates to Tom Carroll <<<<

Tom, I cooked this up this morning... was kinda curious to
see what happens...

Copyright 1993 by R.A. Coates, free to use commercially with
acknowledgement, free for all other use.

DECLARE FUNCTION SEARCHASC& (findstr$, mainstr$)
DECLARE FUNCTION SEARCHSTR& (findstr$, mainstr$)

'===== Define the string to search for
findstr$ = "The quick Brown"
numdup% = 500

'===== Make one really long string to search
FOR c% = 1 TO numdup%
  mainstr0$ = mainstr0$ + "The quick brown fox jumped over the lazy dogs.  "

'      Uppercase "B"rown added to make the string match findstr$
mainstr1$ = "The quick Brown fox jumped over the lazy dogs.  "

FOR c% = 1 TO 2                           'add a couple on the end for humour
  mainstr2$ = mainstr2$ + "The quick brown fox jumped over the lazy dogs.  "

mainstr$ = mainstr0$ + mainstr1$ + mainstr2$
temp% = LEN(mainstr1$)
ofset% = numdup% * temp% + 1                 'calculate the offset for testing
PRINT "Main Program Code"
PRINT "*****************"
PRINT "The Length of the string to search is: "; LEN(mainstr$)
PRINT "The offset to the string to find is: "; ofset%
srchoff& = SEARCHSTR&(findstr$, mainstr$)
srchoff2& = SEARCHASC&(findstr$, mainstr$)
PRINT "Main Program Code"
PRINT "*****************"
PRINT "The offset determined by the SEARCHSTR& is: "; srchoff&
PRINT "The offset determined by the SEARCHASC& is: "; srchoff&

FUNCTION LETFREQ$ (strvar$, pptr%)
  maxweight% = 27
  maxstr$ = " "
  strlen% = LEN(strvar$)
  alphastr$ = "~XxZzYyQqKkJjUuVvNnOoHhEeIiWwGgLlFfMmDdAaBbRrTtPpCcSs "
  FOR c% = 1 TO strlen%
    teststr$ = MID$(strvar$, c%, 1)
    weight% = INSTR(alphastr$, teststr$) \ 2
    IF weight% < maxweight% THEN
      maxweight% = weight%
      maxstr$ = teststr$
    END IF
  NEXT c%
  pptr% = INSTR(strvar$, maxstr$)
  LETFREQ$ = maxstr$

... OS/2:  WINDOZE with bullet-proof glass.
___ Blue Wave/QWK v2.10

--- Maximus 2.00
 * Origin: Durham Systems (ONLINE!) (1:229/110)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET