| Blockland Forums > Modification Help |
| Find The Closet Matching String |
| << < (2/5) > >> |
| Treynolds416:
It seems as if the OP is asking for a simple name completer. For example, I would use it like find("trey"); instead of find("Treynolds416"); The title is a bit misleading, but you would use the above code. If you actually wanted to do something that found the closest string, you would use a different method than posted above. I like to think of it as sort a spell-check idea. One (or more letters, depending on how well you want this to work), would be replaced and cycled through the alphabet until a real word is found. For example, I could type getClosestStr("difine"); and get "define" back. The script would run through lots of combinations: --- Code: ---"aifine" "bifine" "cifine" "eifine" "aifine" ... ... ... "dcfine" "ddfine" "define" STOP --- End code --- You could also make it 'smarter' in that it doesn't try consonants in certain points in the word, to save some computing power. |
| Port:
--- Quote from: Treynolds416 on March 19, 2012, 03:34:53 PM ---until a real word is found --- End quote --- This is the problem. You could have a gigantic list of words, but some things would still be missing and it would take a long time to initialize it anyway. |
| Treynolds416:
--- Quote from: Port on March 20, 2012, 04:28:11 AM ---This is the problem. You could have a gigantic list of words, but some things would still be missing and it would take a long time to initialize it anyway. --- End quote --- Well, you could go the other way, starting with real words and replacing letters until they match the typed word. You could also do a rough sweep at first, to eliminate all of the choices that definitely are not the word, and redefine your sweep criteria over numerous passes. Depending on how well you want it to work, it could be almost infinitely complex |
| jes00:
It already has the list of names in a txt file. I want it to find (if there is one) the closest matching name that I tell it to. |
| Treynolds416:
--- 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 |
| Navigation |
| Message Index |
| Next page |
| Previous page |