Source language: Translate to:

searching a string out of thousand

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Postby Sam Cox » Tue Mar 13, 2007 12:27 pm

This code will let you know whether [Text] appears verbatim in the file. It won't tell you where it is in the file, but it will tell that it is or is not present:
Code: Select all
FileRead "[pubdir]u111.txt" "all" "[EntireFile]"
SearchStr "[#13][Text][#13]" "[#13][EntireFile][#13]" "[Return]"
If "[Return]" ">" "0"
   AlertBox "DEBUG" "Found|[Text]"
Else
   AlertBox "DEBUG" "Not Found|[Text]"
Endif

If you need to know the number of the first line in the file matching [Text], a straightforward approach is:
Code: Select all
FileLen "[pubdir]u111.txt" "[Len]"
SetVar "[LineNumber]" "0"
Loop "1" "[Len]" "[N]"
   FileRead "[pubdir]u111.txt" "[N]" "[Line]"
   If "[Line]" "=" "[Text]"
      SetVar "[LineNumber]" "[N]"
      ExitLoop
   Endif
EndLoop
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Postby Sam Cox » Tue Mar 13, 2007 4:40 pm

You asked if "the [text] written by a user must be exactly the same when the action checks?"

Using only Neobook's built-in commands and without writing a lot of code, the answer is "yes, the [text] must be exactly the same." But. there are some things you can do.

First of all, the task of judging the similarity of non-identical strings is a significant computer science problem. Use Google to search for "string similarity" to see some of the work being done.

1) A simple tactic that you might use is to simplify [text] and the strings to be compared so that non-essential differences are removed. For example, you could do these things:

a) remove all extra spaces
b) remove all punctuation and non-alpha characters
c) convert all characters to lower case

2) A simple string similarity algorithm named Soundex (http://en.wikipedia.org/wiki/Soundex) might interest you. Soundex is a phonetic algorithm for indexing [words] by their sound when pronounced in English. A similarity algorithm based on Soundex would compute a "sound's like" code for each word and compare them to pre-computed codes for the words in each string in u111.txt.

3) Several more complicated and more ambitious similarity algorithms are discussed on-line. They make very interesting reading.

-- Sam
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Postby Sam Cox » Tue Mar 13, 2007 9:32 pm

I think your code will work just fine. I was thinking of something slightly different when I included the [#13] (carriage-return character). I did not test my code. In retrospect I should have used [#13][#10] (carriage-return + linefeed characters), but if your code is working. The major difference between my code and yours is that with your code, the user may type only part of the required response and you will still find it. With my code and the [#13][#10]'s, the user must enter the entire phrase.

-- Sam
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests