Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:53+00:00 2026-05-27T10:59:53+00:00

As of now, I am using this code to open a file and read

  • 0

As of now, I am using this code to open a file and read it into a list and parse that list into a string[]:

string CP4DataBase =
    "C:\\Program\\Line Balancer\\FUJI DB\\KTS\\KTS - CP4 - Part Data Base.txt";
CP4DataBaseRTB.LoadFile(CP4DataBase, RichTextBoxStreamType.PlainText);
string[] splitCP4DataBaseLines = CP4DataBaseRTB.Text.Split('\n');
List<string> tempCP4List = new List<string>();
string[] line1CP4Components;

foreach (var line in splitCP4DataBaseLines)
                    tempCP4List.Add(line + Environment.NewLine);

string concattedUnitPart = "";
foreach (var line in tempCP4List)
{
    concattedUnitPart = concattedUnitPart + line;
    line1CP4PartLines++;
}
line1CP4Components = new Regex("\"UNIT\",\"PARTS\"", RegexOptions.Multiline)
                    .Split(concattedUnitPart)
                    .Where(c => !string.IsNullOrEmpty(c)).ToArray();

I am wondering if there is a quicker way to do this. This is just one of the files I am opening, so this is repeated a minimum of 5 times to open and properly load the lists.

The minimum file size being imported right now is 257 KB. The largest file is 1,803 KB. These files will only get larger as time goes on as they are being used to simulate a database and the user will continually add to them.

So my question is, is there a quicker way to do all of the above code?

EDIT:

***CP4***
"UNIT","PARTS"
"BLOCK","HEADER-"
    "NAME","106536"
    "REVISION","0000"
    "DATE","11/09/03"
    "TIME","11:10:11"
    "PMABAR",""
    "COMMENT",""
    "PTPNAME","R160805"
    "CMPNAME","R160805"
"BLOCK","PRTIDDT-"
    "PMAPP",1
    "PMADC",0
    "ComponentQty",180
"BLOCK","PRTFORM-"
    "PTPSZBX",1.60
    "PTPSZBY",0.80
    "PTPMNH",0.25
    "NeedGlue",0
"BLOCK","TOLEINF-"
    "PTPTLBX",0.50
    "PTPTLBY",0.40
    "PTPTLCL",10
    "PTPTLPX",0.30
    "PTPTLPY",0.30
    "PTPTLPQ",30
"BLOCK","ELDT+"     "PGDELSN","PGDELX","PGDELY","PGDELPP","PGDELQ","PGDELP","PGDELW","PGDELL","PGDELWT","PGDELLT","PGDELCT","PGDELR"
    0,0.000,0.000,0,0,0.000,0.000,0.000,0.000,0.000,0.000,0
"BLOCK","VISION-"
    "PTPVIPL",0
    "PTPVILCA",0
    "PTPVILB",0
    "PTPVICVT",10
    "PENVILIT",0
"BLOCK","ENVDT"
    "ELEMENT","CP43ENVDT-"
        "PENNMI",1.0
        "PENNMA",1.0
        "PENNZN",""
        "PENNZT",1.0
        "PENBLM",12
        "PENCRTS",0
        "PENSPD1",100
        "PTPCRDCT",0
        "PENVICT",1
        "PCCCRFT",1
"BLOCK","CARRING-"
    "PTPCRAPO",0
    "PTPCRPCK",0
    "PTPCRPUX",0.00
    "PTPCRPUY",0.00
    "PTPCRRCV",0
"BLOCK","PACKCLS-"
    "FDRTYPE","Emboss"
    "TAPEWIDTH","8mm"
    "FEEDPITCH",4
    "REELDIAMETER",0
    "TAPEDEPTH",0.0
    "DOADVVACUUM",0
    "CHKBEFOREFEED",0
    "TAPEARMLENGTH",0
    "PPCFDPP",0
    "PPCFDEC",4
    "PPCMNPT",30
"UNIT","PARTS"
"BLOCK","HEADER-"
    "NAME","106653"
    "REVISION","0000"
    "DATE","11/09/03"
    "TIME","11:10:42"
    "PMABAR",""
    "COMMENT",""
    "PTPNAME","0603R"
    "CMPNAME","0603R"
"BLOCK","PRTIDDT-"
    "PMAPP",1
    "PMADC",0
    "ComponentQty",18
"BLOCK","PRTFORM-"
    "PTPSZBX",1.60
    "PTPSZBY",0.80
    "PTPMNH",0.23
    "NeedGlue",0
"BLOCK","TOLEINF-"
    "PTPTLBX",0.50
    "PTPTLBY",0.34
    "PTPTLCL",0
    "PTPTLPX",0.60
    "PTPTLPY",0.40
    "PTPTLPQ",30
"BLOCK","ELDT+"     "PGDELSN","PGDELX","PGDELY","PGDELPP","PGDELQ","PGDELP","PGDELW","PGDELL","PGDELWT","PGDELLT","PGDELCT","PGDELR"
    0,0.000,0.000,0,0,0.000,0.000,0.000,0.000,0.000,0.000,0
"BLOCK","VISION-"
    "PTPVIPL",0
    "PTPVILCA",0
    "PTPVILB",0
    "PTPVICVT",10
    "PENVILIT",0
"BLOCK","ENVDT"
    "ELEMENT","CP43ENVDT-"
        "PENNMI",1.0
        "PENNMA",1.0
        "PENNZN",""
        "PENNZT",1.0
        "PENBLM",12
        "PENCRTS",0
        "PENSPD1",80
        "PTPCRDCT",0
        "PENVICT",1
        "PCCCRFT",1
"BLOCK","CARRING-"
    "PTPCRAPO",0
    "PTPCRPCK",0
    "PTPCRPUX",0.00
    "PTPCRPUY",0.00
    "PTPCRRCV",0
"BLOCK","PACKCLS-"
    "FDRTYPE","Emboss"
    "TAPEWIDTH","8mm"
    "FEEDPITCH",4
    "REELDIAMETER",0
    "TAPEDEPTH",0.0
    "DOADVVACUUM",0
    "CHKBEFOREFEED",0
    "TAPEARMLENGTH",0
    "PPCFDPP",0
    "PPCFDEC",4
    "PPCMNPT",30

… the file goes on and on and on.. and will only get larger.

The REGEX is placing each “UNIT PARTS” and the following code until the NEXT “UNIT PARTS” into a string[].
After this, I am checking each string[] to see if the “NAME” section exists in a different list. If it does exist, I am outputting that “UNIT PARTS” at the end of a textfile.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:59:53+00:00Added an answer on May 27, 2026 at 10:59 am

    This bit is a potential performance killer:

    string concattedUnitPart = "";
    foreach (var line in tempCP4List)
    {
        concattedUnitPart = concattedUnitPart + line;
        line1CP4PartLines++;
    }
    

    (See this article for why.) Use a StringBuilder for repeated concatenation:

    // No need to use tempCP4List at all
    StringBuilder builder = new StringBuilder();
    foreach (var line in splitCP4DataBaseLines)
    {
        concattedUnitPart.AppendLine(line);
        line1CP4PartLines++;
    }
    

    Or even just:

    string concattedUnitPart = string.Join(Environment.NewLine,
                                           splitCP4DataBaseLines);
    

    Now the regex part may well also be slow – I’m not sure. It’s not obvious what you’re trying to achieve, whether you need regular expressions at all, or whether you really need to do the whole thing in one go. Can you definitely not just process it line by line?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this code import re file = open('FilePath/OUTPUT.01') lines = file.read() file.close() for match
I altered my code so I could open a file as read only. Now
I'm using this code now echo $form->input('username'); How do I make sure the label
This is the snippet of code i'm using now: def countOccurences(a, b) #counts the
I have student.xml file and am parsing this file using SAX Parser and now
I'm always surprised that even after using C# for all this time now, I
I'm using TinyXML to parse/build XML files. Now, according to the documentation this library
I have code using boost to list directory contents, iterate through each file, and
In Python 2.5 I stored data using this code: def GLWriter(file_name, string): import cPickle
Right now I am using this to export a repeater (with multiple nested repeaters)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.