PDA

View Full Version : How to ignore line starting by # caractere


idiogene
10-02-2006, 02:53 PM
Hi,
I'm trying to populate a listbox with an m3U (playlist) file. The purpose of this is to pick and launch a song from that listbox in the media player.

The script I use is:

function playlist()
ListBox.DeleteItem("ListBox1",-1);
tbFiles = TextFile.ReadToTable();
for i,v in tbFiles do
ListBox.AddItem("ListBox1", String.SplitPath(v).Filename, v);
end
end

Every things work fine with the script except that the list include with each song a line of caractere that I wish to eliminate. In the example below these lines start by #EXTINF...

ex:
#EXTM3U
#EXTINF:248,Bill Evans - Nancy (with the Laughing Face)
Bill Evans - Nancy (with the Laughing Face)
#EXTINF:351,Bill Evans - Nardis
Bill Evans - Nardis
#EXTINF:490,Bill Evans - No Cover, No Minimum
Bill Evans - No Cover, No Minimum
etc.

I found a tread in this forum arguing that AMS could ignore lines with # at the beginning of the line. Could anyone help me with the necessary code to do so that the result will appear like this in the listbox.

Bill Evans - Nancy (with the Laughing Face)
Bill Evans - Nardis
Bill Evans - No Cover, No Minimum
etc.

Thanks

D.

Lorne
10-02-2006, 03:11 PM
Something like this might work:

function playlist()
ListBox.DeleteItem("ListBox1",-1);
tbFiles = TextFile.ReadToTable();
for i,v in tbFiles do
if(String.Left(v, 1) ~= "#") then
ListBox.AddItem("ListBox1", String.SplitPath(v).Filename, v);
end
end
end

TJ_Tigger
10-02-2006, 03:12 PM
NM. Lorne beat me to it.

idiogene
10-02-2006, 03:33 PM
Yess so simple and logic.

Many thanks Lorne for your help.

TJ_Tigger
10-02-2006, 03:42 PM
You can also use the lua string.find to look for lines that begin with a # and ignore them.

function playlist()
ListBox.DeleteItem("ListBox1",-1);
tbFiles = TextFile.ReadToTable();
for i,v in tbFiles do
if not string.find(v, "^#") then
ListBox.AddItem("ListBox1", String.SplitPath(v).Filename, v);
end
end
end

TJ_Tigger
10-02-2006, 03:46 PM
And this should ignore leading space characters. You could do the same thing using String.Trim within AMS.

function playlist()
ListBox.DeleteItem("ListBox1",-1);
tbFiles = TextFile.ReadToTable();
for i,v in tbFiles do
if not string.find(v, "%S^#") then
ListBox.AddItem("ListBox1", String.SplitPath(v).Filename, v);
end
end
end

The %S is a capital S which says ignore space characters

idiogene
10-02-2006, 06:46 PM
Very well TJ-Tigger,
It's also getting the job done. I can figure how it works now.
Thank you Sir. There's a lot to learn in here.
D.