何百万行もの複数のファイルを読み込んでおり、特定の問題があるすべての行番号のリストを作成しています。たとえば、特定のフィールドが空白のままであったり、無効な値が含まれている場合です。
したがって、私の質問は、行数が 100 万を超える可能性がある数値のリストを追跡するための最も効率的な日付型は何かということです。String Builder、Lists、またはその他のものを使用すると、より効率的になりますか?
私の最終的な目標は、「特定のフィールドが 1-32、40、45、47、49-51 などで空白になっている」のようなメッセージを出力することです。 is is only 1 more I would change it from 1 to 1-2 and if it’s more than one willse a a comma. リストでは、各番号をリストに追加し、ファイルが作成されたら結合します。ただし、この場合、何百万もの数字を含む複数のリストを作成できます。
String Builder を使用して数値のリストを結合するために使用している現在のコードは次のとおりです。
string currentLine = sbCurrentLineNumbers.ToString();
string currentLineSub;
StringBuilder subCurrentLine = new StringBuilder();
StringBuilder subCurrentLineSub = new StringBuilder();
int indexLastSpace = currentLine.LastIndexOf(' ');
int indexLastDash = currentLine.LastIndexOf('-');
int currentStringInt = 0;
if (sbCurrentLineNumbers.Length == 0)
{
sbCurrentLineNumbers.Append(lineCount);
}
else if (indexLastSpace == -1 && indexLastDash == -1)
{
currentStringInt = Convert.ToInt32(currentLine);
if (currentStringInt == lineCount - 1)
sbCurrentLineNumbers.Append("-" + lineCount);
else
{
sbCurrentLineNumbers.Append(", " + lineCount);
commaCounter++;
}
}
else if (indexLastSpace > indexLastDash)
{
currentLineSub = currentLine.Substring(indexLastSpace);
currentStringInt = Convert.ToInt32(currentLineSub);
if (currentStringInt == lineCount - 1)
sbCurrentLineNumbers.Append("-" + lineCount);
else
{
sbCurrentLineNumbers.Append(", " + lineCount);
commaCounter++;
}
}
else if (indexLastSpace < indexLastDash)
{
currentLineSub = currentLine.Substring(indexLastDash + 1);
currentStringInt = Convert.ToInt32(currentLineSub);
string charOld = currentLineSub;
string charNew = lineCount.ToString();
if (currentStringInt == lineCount - 1)
sbCurrentLineNumbers.Replace(charOld, charNew);
else
{
sbCurrentLineNumbers.Append(", " + lineCount);
commaCounter++;
}
}