| Blockland Forums > Modification Help |
| Find The Closet Matching String |
| << < (5/5) |
| Nexus:
--- Quote from: jes00 on March 21, 2012, 09:25:27 PM ---That's not too useful because as it is strCom() does not exist. --- End quote --- I basically handed you the entire everything except that, because there wasn't much you were doing right. I am assuming strstr was the comparison function you could maybe figure out how to adapt to that code, because I have never used it before. Ok looking at strstr, it doesn't seem very useful at all. I might write you up some version of the strcom() thing if I have time. Edit: this might work function strcom(%sa, %sb) { if(%sa $= %sb) return 1; if(%sa $= "" || %sb $= "") return 0; if(strlen(%sb) > strlen(%sa)) { %temp = %sa; %sa = %sb; %sb = %temp; } if(strpos(%sa, %sb) > -1) { %leftovers = strlen(%sa) - strlen(%sb); %acc = 1 - strlen(%sa)/%leftovers; return %acc; } return 0; } |
| Treynolds416:
Goddamn it jes we aren't going to spoon feed you the answer here. Use a bit of logic, I got a version to work in a matter of minutes. I've already told you why the way you are trying to do is flawed Edit: @Nexus the strStr if statement will grab the first match it finds, yes. This is potentially a problem, absolutely. Jes can write his own string comparison function (like you said) if he needs this function to work better than just grabbing the first match. |
| Ipquarx:
Check how many charachters in a row from the second string match the charachters in the first string, with a larger priority on the beginning than the middle or end. Then divide that number by the total charachter count. It's just an idea, but i'm pretty sure thats how the findclientbyname function does it. |
| Nexus:
--- Quote from: Ipquarx on March 22, 2012, 07:19:45 PM ---Check how many charachters in a row from the second string match the charachters in the first string, with a larger priority on the beginning than the middle or end. Then divide that number by the total charachter count. It's just an idea, but i'm pretty sure thats how the findclientbyname function does it. --- End quote --- No, findclientbyname is literally a single strpos() for each name and returns the lowest one besides -1, if it even compares to find the one with the earliest match Also I think the strcom() I wrote up should do the trick just fine. |
| Navigation |
| Message Index |
| Previous page |