Author Topic: Word Searcher  (Read 3480 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Word Searcher
« on: May 18, 2019, 12:16:46 pm »
A quick program I wrote, from a discussion in the chat room:

Code: [Select]
SCREEN _NEWIMAGE(800, 600, 32)

REDIM wordlist(1000000) AS STRING
OPEN "Scrabble WordList 2006.txt" FOR BINARY AS #1
DO UNTIL EOF(1)
    wordcount = wordcount + 1
    LINE INPUT #1, wordlist(wordcount)
LOOP
REDIM _PRESERVE wordlist(wordcount)
CLOSE

DO
    INPUT "Search term:"; search$
    search$ = UCASE$(search$)
    s$ = LEFT$(search$, 3)
    m$ = _TRIM$(MID$(search$, 4))
    l = LEN(m$)
    SELECT CASE s$
        CASE "BEG"
            PRINT "Words beginning with: "; m$
            FOR i = 1 TO wordcount
                IF LEFT$(wordlist(i), l) = m$ THEN PRINT wordlist(i),
            NEXT
        CASE "END"
            PRINT "Words ending with: "; m$
            FOR i = 1 TO wordcount
                IF RIGHT$(wordlist(i), l) = m$ THEN PRINT wordlist(i),
            NEXT
        CASE "CON"
            PRINT "Words containing: "; m$
            FOR i = 1 TO wordcount
                IF INSTR(wordlist(i), m$) THEN PRINT wordlist(i),
            NEXT
        CASE ELSE
            END
    END SELECT
    PRINT
    PRINT "**********************"
    PRINT
LOOP

this does a search of our word lists for the following:

BEG xxxxx -- words beginning with "xxxxx"
END xxxxx -- words ending with "xxxxx"
CON xxxxx -- words which contain "xxxxx"

So to see which words begin with "THEN", we simply do a search for "BEG THEN".
To see which words end with "THEN", we do a search for "END THEN".
And to see which words contain "THEN" in them, we do a search for "CON THEN".

That's all there is to it.  :D
* Scrabble WordList 2006.txt (Filesize: 1.85 MB, Downloads: 345)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Word Searcher
« Reply #1 on: May 18, 2019, 01:26:04 pm »
Hi Steve

It's fine, so I have thought that it would be nice a Windowed version and not only a COMMANDLINE version just old Linuxes... so I have used Inform where I posted the Informed version...
Programming isn't difficult, only it's  consuming time and coffee