Shortest way to remove empty lines?
Posted: 08 Sep 2011 17:59
After reading a file into a variable and removing the content of a few lines via a regex (for e.g. an .m3u playlist file) is there a single command which can be used to remove all these empty lines?
This is my current (ugly) version:
I tried to do it with different regexpressions (\r\n$, etc.) and hoped that formatlist could do this as well (with format "e") but I haven't found an easier way yet.
This is my current (ugly) version:
Code: Select all
$PlaylistFile = readfile("<curitem>");
// Remove all unnecessary data
$CleanupPlaylist = regexreplace("$PlaylistFile", "^#.*$", "");
// Replace the separator
replace $CleanupPlaylist, $CleanupPlaylist, "<crlf>", "|";
// Target linebreaks
$Linebreaks = substr("$CleanupPlaylist", 0, 1);
// Remove all linebreaks
replace $UnsortedPlaylist, $CleanupPlaylist, "$Linebreaks", "";