Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function IsWord%(test$)
#6
(02-25-2026, 08:58 PM)bplus Wrote: Inspired by mdijkens comment here: https://qb64phoenix.com/forum/showthread...9#pid40209

This is really easy way to confirm if a word is in a file list of words say from Collins Dictionary:
Code: (Select All)
_Title "Test IsWord function" 'bplus 2026-02-25
Dim Shared FStr$
FStr$ = _ReadFile$("Words.txt") ' once and for all time
While 1
    Input "Enter a word to see if in Collins Dictionary"; w$
    If IsWord%(w$) Then Print w$; ", is a word." Else Print w$; ", is Not a word"
Wend
Function IsWord% (test$)
    testeol$ = Chr$(13) + Chr$(10) + UCase$(test$) + Chr$(13) + Chr$(10)
    If InStr(FStr$, testeol$) Then IsWord% = -1 Else IsWord% = 0
End Function

"Words.txt" is a text file using CRLF's to end lines. All I had to do was insert a blank line at beginning of file so that the word "AA" could be verified as a word from the file.

This is way better IMHO than using a Random Access file!

Here is the file to run your own tests:
That's indeed what I had in mind. (dont forget FStr$ = Chr$(13) + Chr$(10) +  ReadFile$("Words.txt") to also find first word in file)

I fully agree with approach of Steve to load list in array, but that depends if you need/prefer efficiency and speed over short simple code. If you need to search 1000's of time, then better make a list array
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply


Messages In This Thread
Function IsWord%(test$) - by bplus - 02-25-2026, 08:58 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 09:27 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 10:16 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 10:25 PM
RE: Function IsWord%(test$) - by bplus - 02-25-2026, 11:34 PM
RE: Function IsWord%(test$) - by mdijkens - 02-26-2026, 02:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Zeller's congruence pass 3: test day-of-week calculation algorythms for accuracy TDarcos 0 1,099 10-23-2024, 05:04 PM
Last Post: TDarcos
  Test sorting algorithms eoredson 3 972 05-04-2023, 09:38 PM
Last Post: eoredson
  Long Date Function AtomicSlaughter 2 972 05-24-2022, 08:22 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)