Advertisement
Zektrix1

Search For Match Based On Score

Sep 29th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Search := "lem"
  2.  
  3. Data := ["Tuna",
  4. "Carrots",
  5. "Lemon",
  6. "How's it going?"
  7. ]
  8.  
  9. Data_Score := []
  10.  
  11. If !Search
  12. {
  13. MsgBox "Nothing Returns Nothing"
  14. Return
  15. }
  16. Loop DATA.Length
  17. {
  18. Score_Keeper := 0
  19.  
  20. Search_Array := StrSplit(Search)
  21. Search_Length := StrLen(Search)
  22.  
  23. Data_Array := StrSplit(Data[A_Index])
  24. Data_Length := StrLen(Data[A_Index])
  25. If (Data_Length = Search_Length)
  26. {
  27. Loop Search_Length
  28. {
  29. If (Data_Array[A_Index] != Search_Array[A_Index])
  30. Score_Keeper++
  31. }
  32. }
  33. Else If (Data_Length > Search_Length)
  34. {
  35. Loop Data_Length - Search_Length
  36. Score_Keeper++
  37. Loop Search_Length
  38. {
  39. If (Data_Array[A_Index] != Search_Array[A_Index])
  40. Score_Keeper++
  41. }
  42. Data_Score.Push Score_Keeper
  43. }
  44. Else If (Search_Length > Data_Length)
  45. {
  46. Loop Search_Length - Data_Length
  47. Score_Keeper++
  48. Loop Data_Length
  49. {
  50. If (Data_Array[A_Index] != Search_Array[A_Index])
  51. Score_Keeper++
  52. }
  53. Data_Score.Push Score_Keeper
  54. }
  55. }
  56. Loop Data_Score.Length
  57. {
  58. If Data_Score[A_Index] = Min(Data_Score*)
  59. Top_Match := Data[A_Index]
  60. }
  61. MsgBox Top_Match
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement