C# 查找需要更新/删除的行的索引,然后处理该文件。你提到的也很好。这些文件有数十万行,所以我认为它们对于这个方法来说太大了(至少对于我的pc:),仍然感谢第六点中的一些建议。 Order Code|Stock ACREPAIR|1031 AF813|18 AF

C# 查找需要更新/删除的行的索引,然后处理该文件。你提到的也很好。这些文件有数十万行,所以我认为它们对于这个方法来说太大了(至少对于我的pc:),仍然感谢第六点中的一些建议。 Order Code|Stock ACREPAIR|1031 AF813|18 AF,c#,file,replace,C#,File,Replace,查找需要更新/删除的行的索引,然后处理该文件。你提到的也很好。这些文件有数十万行,所以我认为它们对于这个方法来说太大了(至少对于我的pc:),仍然感谢第六点中的一些建议。 Order Code|Stock ACREPAIR|1031 AF813|18 AF823|12 AFCOB11|21 AFCS300|33 AFCS3000|1 AFEM4|5 AFOMNI|17 AFOX2|-3 AFOX3|-3 AFROD|28 AFSENSOR|50 AFUF21|24 AN00001|-1 AN00


查找需要更新/删除的行的索引,然后处理该文件。你提到的也很好。这些文件有数十万行,所以我认为它们对于这个方法来说太大了(至少对于我的pc:),仍然感谢第六点中的一些建议。
Order Code|Stock
ACREPAIR|1031
AF813|18
AF823|12
AFCOB11|21
AFCS300|33
AFCS3000|1
AFEM4|5
AFOMNI|17
AFOX2|-3
AFOX3|-3
AFROD|28
AFSENSOR|50
AFUF21|24
AN00001|-1
AN00002|21
AN00003|4
AN00004|4
AN00005|9
...
Action,CategoryPath,ID,Name,Code,Stock
"Product","Home > Opto-electronics > LED > Standard LED, Multicolour",2226,"KINGBRIGHT LED, 3MM, HE-RED/GRN L-93WEGW","SC07621",202
"Product","Home > Resistors > Fixed",2228,"VISHAY DRALORIC RESISTOR, 0402, 5%, 10K0 CRCW040210K0JNEAIF","RE06211",0
"Product","Home > Resistors > Fixed",2229,"VISHAY DRALORIC RESISTOR, 0402, 5%, 3R90 CRCW04023R90JNEAIF","RE06212",0
"Product","Home > Resistors > Fixed",2230,"VISHAY DRALORIC RESISTOR, 0402, 5%, 2R70 CRCW04022R70JNEAIF","RE06220",25
"Product","Home > Resistors > Fixed",2231,"VISHAY DRALORIC RESISTOR, 0402, 5%, 33R0 CRCW040233R0JNEAIF","RE06221",0
"Product","Home > Resistors > Fixed",2232,"VISHAY DRALORIC RESISTOR, 0402, 5%, 100R CRCW0402100RJNEAIF","RE06226",0
"Product","Home > IC's > Comparators",2234,"STMICROELECTRONICS IC, COMPARATOR DUAL, DIP8, 393 LM393N","SC10207",57
"Product","Home > IC's > Amplifiers > Operational",2237,"STMICROELECTRONICS OP AMP, QUAD JFET, DIP14 TL084CN","SC07929",82
"Product","Home > IC's > Amplifiers > Audio Power",2239,"NATIONAL SEMICONDUCTOR AMP, AUDIO 0.25W, DIP8, 386 LM386N-1","SC08430",83
"Product","Home > IC's > Microcontrollers",2241,"MICROCHIP 8BIT FLASH MCU, 12F675, DIP8 PIC12F675-I/P","ACREPAIR",16
...
var items = File.ReadAllLines("file1.txt").
    Skip(1).
    Select(s =>
    {
        var strings = s.Split('|');
        if (strings.Length != 2) throw new FormatException();
        return new {Code = strings[0], Stock = Convert.ToInt32(strings[1])};
    }).
    ToArray();
var compareTo = File.ReadAllLines("file2.txt").
    Skip(1).
    Select(s =>
    {
        var strings = s.Split(',');
        if (strings.Length != 6) throw new FormatException();
        return new {Code = strings[4].Trim('"'), Stock = Convert.ToInt32(strings[5])};
    }).
    ToArray();
//You can use Intersect after having defined your EqualityComparer, 
//avoid anonymous types in your final code
foreach (var item in items.Where(i => compareTo.Any(i2 => i.Code == i2.Code)))
{
    //Operate, be aware that compareTo is dissociated from your original file
    //So you'll have to adapt the above approach for your needs.
}
List<string[]> stock = new List<string[]>(File.ReadAllLines("G:\\Stock.txt").Select(line => line.Split('|')));
List<string[]> products = new List<string[]>(File.ReadAllLines("G:\\Products.txt").Select(line => line.Split(',')));

products.ForEach(p =>
{
    // since not all arrays in this case are the same lenght, we will go backwards from the end
    int productStockIndex = Array.IndexOf(p, p.Last());

    // product name is before the stock count
    int productNameIndex = productStockIndex - 1;

    // get product name to find in Stock.txt and remove extra quotes from product name
    string productName = p[productNameIndex].Replace("\"", "");

    // check if Stock.txt contains the product
    if (stock.Any(s => s[0] == productName))
    {
        // Update the stock count
        p[productStockIndex] = stock.First(stk => stk[0] == productName)[1];
    }       
});