リストの最初と最後にある空の行をすべて削除する必要List<string>
があります。
注: 空行はコンテンツのない行と見なされますが、空白とタブが含まれる可能性があります。これは、行が空かどうかを確認する方法です。
private bool HasContent(string line)
{
if (string.IsNullOrEmpty(line))
return false;
foreach (char c in line)
{
if (c != ' ' && c != '\t')
return true;
}
return false;
}
それを行うために、どのような効率的で読みやすいコードを提案しますか?
確認例
[" ", " ", " ", " ", "A", "B", " ", "C", " ", "D", " ", " ", " "]
このようなリストは、次の結果の最初と最後にあるすべての空行を削除して、トリミングする必要があります。
["A", "B", " ", "C", " ", "D"]