S
Sems
Hi all
I'm looking for some feedback / suggestions on how to write a piece of
code in a better way.
The below code works but I want to write it using query syntax to to
get rid of the nested loops. How would I do this?
The code builds up a list of urls that do not end in the extentions
listed in the nonIncludedExts strings.
I know this can be done in a cleaner way but am not sure of the best
approach.
Thanks
List<string> parsedData = new List<string>();
using (StreamReader readFile = new StreamReader(path))
{
string nonIncludedExts =
".js .gif .css .axd .png .txt .ico .flv .jpg .swf"
string[] splitExts = nonIncludedExts.Split(new
char[] { ' ' });
string line;
while ((line = readFile.ReadLine()) != null)
{
bool endsWithExcludedExt = false;
foreach (string ext in splitExts)
{
if (line.EndsWith(ext))
endsWithExcludedExt = true;
}
if (!endsWithExcludedExt)
{
parsedData.Add(line);
}
}
}
I'm looking for some feedback / suggestions on how to write a piece of
code in a better way.
The below code works but I want to write it using query syntax to to
get rid of the nested loops. How would I do this?
The code builds up a list of urls that do not end in the extentions
listed in the nonIncludedExts strings.
I know this can be done in a cleaner way but am not sure of the best
approach.
Thanks
List<string> parsedData = new List<string>();
using (StreamReader readFile = new StreamReader(path))
{
string nonIncludedExts =
".js .gif .css .axd .png .txt .ico .flv .jpg .swf"
string[] splitExts = nonIncludedExts.Split(new
char[] { ' ' });
string line;
while ((line = readFile.ReadLine()) != null)
{
bool endsWithExcludedExt = false;
foreach (string ext in splitExts)
{
if (line.EndsWith(ext))
endsWithExcludedExt = true;
}
if (!endsWithExcludedExt)
{
parsedData.Add(line);
}
}
}