Blockland Forums > Modification Help
Find The Closet Matching String
<< < (3/5) > >>
jes00:

--- Quote from: Treynolds416 on March 20, 2012, 04:11:24 PM ---
--- Code: ---function find(%str)
{
//File I/O stuff
%line = %file.readline();
if(strStr(%line,%str) != -1 && strLen(%str) <= strLen(%line))
return %line;
        else
                return 0;
//More File I/O stuff
}
--- End code ---
This is very rudimentary code, but I'm pretty sure it will work for what you want to do

It assumes several things:
1) You have one name on each line in the text file, nothing more and nothing less
2) What you type into find(); will always have less or equal number of letters than the name on the line
3) What you type into find(); will always be part of a name, with no misspelled or misplaced characters

--- End quote ---
Hmm, this is not working.

--- Code: ---function getID(%name)
{
%file = new FileObject();
%file.openForRead("config/Client/ChatBot/BL_IDs.txt");

while(!%file.isEOF())
{
%badName = %file.readLine();
%ID = %file.readLine();
%blank = %file.readLine();

if(strStr(%badName, %name) != -1 && strLen(%name) <= strLen(%ID))
{
%file.close();
%file.delete();

return %ID;
}

%file.close();
%file.delete();

return %ID;
}

%file.close();
%file.delete();

return;
}

--- End code ---
Treynolds416:
Why have you tried to close the file (2 times) in the while statement?
jes00:

--- Quote from: Treynolds416 on March 21, 2012, 10:17:54 AM ---Why have you tried to close the file (2 times) in the while statement?

--- End quote ---
Because it returns and when it returns it ends the function.
Treynolds416:

--- Quote from: Treynolds416 on March 21, 2012, 10:17:54 AM ---Why have you tried to close the file (2 times) in the while statement?

--- End quote ---
My point is that you don't need several returns

Edit: I just took a better look at your code. Why also are you setting three variables to %file.readLine();?
Jasa1:
stripos("Hello my name is jes00","jes");
This would return 17.
Navigation
Message Index
Next page
Previous page

Go to full version