String Patterns/Song Filtering

I’m making a filter that’ll go through all the song titles/artists and filter out those that don’t have the name. Here’s the code:

[lua]filter.OnTextChanged = function()
local str = string.lower(filter:GetValue())
if str == “” then
for k,v in ipairs(removed) do
songs:AddLine(v[1],v[2],v[3],v[4])
table.remove(removed,k)
end
else
for k,v in ipairs(songs:GetLines()) do
local v1,v2 = string.lower(v:GetValue(1)),string.lower(v:GetValue(2))
if !string.find(v1,str) and !string.find(v2,str) then
table.insert(removed,{v:GetValue(1),v:GetValue(2),v:GetValue(3),v:GetValue(4)})
songs:RemoveLine(k)
end
end

	for k,v in ipairs(removed) do
		if string.find(string.lower(v[1]),str) or string.find(string.lower(v[2]),str) then
			songs:AddLine(v[1],v[2],v[3],v[4])
			table.remove(removed,k)
		end
	end
end

end[/lua]

If I type in one letter, it filters it out correctly. However, if I try more than one letter it doesn’t work. How am I searching the strings wrongly?

Apologies for the bump, but I really need some help on this one.

Maybe you could post the whole thing.

Other than the creation of the “songs” DListView and the “removed” table, there’s nothing else that you really need to see.

That’s exactly what I need to see since I (and other people reading) have absolutely no clue what the content of the table you’re filtering is. (which field is what)

Ok then. Here’s that stuff:


local songlist = {
{"http://www.jasmynecannick.com/music/I_Got%20A_Feeling.mp3"},
{"http://theoffspring.us/files/audio/albums/2008%20-%20Rise%20And%20Fall,%20Rage%20And%20Grace%20(320)/03-You_Gonna_Go_Far,_Kid_www.theoffspring.us.mp3"},
{"http://centralvillage.blogs.com/cv/files/still_alive.mp3"},
{"http://teamvirtue.org/media/cbyr-Victims_of_Science_-_The_Device_Has_Been_Modified.mp3"},
{"http://www.1scottentertainment.com/music/Red%20Hot%20Chili%20Peppers%20-%20Under%20the%20bridge.mp3"},
{"http://www.goodfellastatts.com/Enter.mp3"},
{"http://azvert.com/Music/Foo%20Fighters%20-%20Long%20Road%20To%20Ruin.mp3"},
{"http://kaius.free.fr/daftpunk.mp3"},
{"http://www.youtube.com/watch?v=IEtqWhyR2Ic&autoplay=1","Guitar Piano","Anonymous","Guitar"},
}

for k,v in ipairs(songlist) do
	if v[2] and v[3] and v[4] and v[5] and v[6] and v[7] then 
		local line = songs:AddLine(v[2],v[3],v[4],SecToMin(v[5]))
		line.URL = v[1]
	else
		if !file.Exists("../lua/includes/modules/gm_bass.dll") or !ValidURL(v[1]) then
			local t = ""
			if v[5] then t = SecToMin(v[5]) end
			local line = songs:AddLine(v[2] or "Unknown Title",v[3] or "Get the gm_bass module",v[4] or "",t)
			line.URL = v[1]
		else		
			BASS.StreamFileURL(v[1],0,function(ch)
				if not ch then ErrorNoHalt("URL NOT VALID: "..v[1].."
") return end
				local line = songs:AddLine(ch:gettag("%TITL"),ch:gettag("%ARTI"),string.Replace(ch:gettag("%GNRE"),"/",""),SecToMin(math.floor(ch:getlength())))
				line.URL = v[1]
				songlist[k]={v[1],ch:gettag("%TITL"),ch:gettag("%ARTI"),string.Replace(ch:gettag("%GNRE"),"/",""),math.floor(ch:getlength()),ch:gettag("%ALBM"),ch:gettag("%YEAR")}
			end)
		end
	end
end