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 6137327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:42:42+00:00 2026-05-23T17:42:42+00:00

I have a file with data in it that I would like to split

  • 0

I have a file with data in it that I would like to split up into three different ListBoxes. I want the first ListBox to contain all of the data (a new list item for every line of data read from the text document).

Main ListBox:

D1
D2
C9
R7
R1
C130
D99
Q9

Second ListBox: (after a regex was used to match values that start with D)

D1
D2
D99

Third ListBox: (after a regex was used to match values that start with C)

C9
C130

And after those values were matched for the SECOND and THIRD ListBoxes, the

New Main ListBox will look like this:

R7
R1
Q9  

CODE

    static List<string> findPackagePlacementOneType(List<string> list)
    {
        // Creates a new list to return with new format.
        var result = new List<string>();

        // Checks each line in the list.
        foreach (var line in list)
        {
            // PLACEMENT ONE Regex
            Match regexRES = Regex.Match(line, @"^.+(RES)");
            Match regex0402 = Regex.Match(line, @"^.+(0402)");
            Match regex0201 = Regex.Match(line, @"^.+(0201)");
            Match regex0603 = Regex.Match(line, @"^.+(0603)");
            Match regex0805 = Regex.Match(line, @"^.+(0805)");
            Match regex1206 = Regex.Match(line, @"^.+(1206)");
            Match regex1306 = Regex.Match(line, @"^.+(1306)");
            Match regex1608 = Regex.Match(line, @"^.+(1608)");
            Match regex3216 = Regex.Match(line, @"^.+(3216)");
            Match regex2551 = Regex.Match(line, @"^.+(2551)");
            Match regex1913 = Regex.Match(line, @"^.+(1913)");
            Match regex1313 = Regex.Match(line, @"^.+(1313)");
            Match regex2513 = Regex.Match(line, @"^.+(2513)");
            Match regex5125 = Regex.Match(line, @"^.+(5125)");
            Match regex2525 = Regex.Match(line, @"^.+(2525)");
            Match regex5619 = Regex.Match(line, @"^.+(5619)");
            Match regex3813 = Regex.Match(line, @"^.+(3813)");
            Match regex1508 = Regex.Match(line, @"^.+(1508)");
            Match regex6431 = Regex.Match(line, @"^.+(6431)");
            Match regex2512 = Regex.Match(line, @"^.+(2512)");
            Match regex1505 = Regex.Match(line, @"^.+(1505)");
            Match regex2208 = Regex.Match(line, @"^.+(2208)");
            Match regex1005 = Regex.Match(line, @"^.+(1005)");
            Match regex1010 = Regex.Match(line, @"^.+(1010)");
            Match regex2010 = Regex.Match(line, @"^.+(2010)");
            Match regex0505 = Regex.Match(line, @"^.+(0505)");
            Match regex0705 = Regex.Match(line, @"^.+(0705)");
            Match regex1020 = Regex.Match(line, @"^.+(1020)");
            Match regex1812 = Regex.Match(line, @"^.+(1812)");
            Match regex2225 = Regex.Match(line, @"^.+(2225)");
            Match regex5764 = Regex.Match(line, @"^.+(5764)");
            Match regex4532 = Regex.Match(line, @"^.+(4532)");
            Match regex1210 = Regex.Match(line, @"^.+(1210)");
            Match regex0816 = Regex.Match(line, @"^.+(0816)");
            Match regex0363 = Regex.Match(line, @"^.+(0363)");
            Match regexSOT = Regex.Match(line, @"^.+(SOT)");

            if (regexRES.Success || regex0402.Success || regex0201.Success || regex0603.Success ||
                regex0805.Success || regex1206.Success || regex1306.Success || regex1608.Success ||
                regex3216.Success || regex2551.Success || regex1913.Success || regex1313.Success ||
                regex2513.Success || regex5125.Success || regex2525.Success || regex5619.Success ||
                regex3813.Success || regex1508.Success || regex6431.Success || regex2512.Success ||
                regex1505.Success || regex2208.Success || regex1005.Success || regex1010.Success ||
                regex2010.Success || regex0505.Success || regex0705.Success || regex1020.Success ||
                regex1812.Success || regex2225.Success || regex5764.Success || regex4532.Success ||
                regex1210.Success || regex0816.Success || regex0363.Success || regexSOT.Success)
            {
                result.Add(string.Join(" ", line));
            }

            else
                result.Remove(line);
        }

        // Returns the new list so it can be formatted further.
        return result;
    }

    // Finds the placement 2 package types.
    static List<string> findPackagePlacementTwoType(List<string> list)
    {
        // Creates a new list to return with new format.
        var result = new List<string>();

        // Checks each line in the list.
        foreach (var line in list)
        {
            // PLACEMENT TWO Regex
            Match regexBGA = Regex.Match(line, @"^.+(BGA)");
            Match regexSOP8 = Regex.Match(line, @"^.+(SOP8)");
            Match regexQSOP = Regex.Match(line, @"^.+(QSOP)");
            Match regexTQSOP = Regex.Match(line, @"^.+(TQSOP)");
            Match regexSOIC16 = Regex.Match(line, @"^.+(SOIC16)");
            Match regexSOIC12Plus = Regex.Match(line, @"^.+(SOIC12)");
            Match regexSOIC8 = Regex.Match(line, @"^.+(SOIC8)");
            Match regexSO8 = Regex.Match(line, @"^.+(SO8)");
            Match regexSO08 = Regex.Match(line, @"^.+(SO08)");
            Match regexCQFP = Regex.Match(line, @"^.+(CQFP)");
            Match regexLCC = Regex.Match(line, @"^.+(LCC)");
            Match regexLGA = Regex.Match(line, @"^.+(LGA)");
            Match regexOSCCC = Regex.Match(line, @"^.+(OSCCC)");
            Match regexPLCC = Regex.Match(line, @"^.+(PLCC)");
            Match regexQFN = Regex.Match(line, @"^.+(QFN)");
            Match regexQFP = Regex.Match(line, @"^.+(QFP)");
            Match regexSOJ = Regex.Match(line, @"^.+(SOJ)");
            Match regexSON = Regex.Match(line, @"^.+(SON)");

            if (regexBGA.Success || regexSOP8.Success || regexQSOP.Success || regexTQSOP.Success ||
               regexSOIC16.Success || regexSOIC12Plus.Success || regexSOIC8.Success || regexSO8.Success ||
               regexSO08.Success || regexCQFP.Success || regexLCC.Success || regexLGA.Success ||
               regexOSCCC.Success || regexPLCC.Success || regexQFN.Success || regexQFP.Success ||
               regexSOJ.Success || regexSON.Success)
            {
                result.Add(string.Join(" ", line));
            }

            else
                result.Remove(line);
        }

        // Returns the new list so it can be formatted further.
        return result;
    }

    static List<string> findPackagePlacementChoiceType(List<string> list)
    {
        // Creates a new list to return with new format.
        var result = new List<string>();

        // Checks each line in the list.
        foreach (var line in list)
        {
            // PLACEMENT CHOICE Regex
            Match regexCAP = Regex.Match(line, @"^.+(CAP)");
            Match regexIND = Regex.Match(line, @"^.+(IND)");
            Match regexMELF = Regex.Match(line, @"^.+(MELF)");
            Match regexDIOM = Regex.Match(line, @"^.+(DIOM)");
            Match regexSOD = Regex.Match(line, @"^.+(SOD)");
            Match regexSTO = Regex.Match(line, @"^.+(STO)");
            Match regexTO = Regex.Match(line, @"^.+(TO)");

            if (regexCAP.Success || regexIND.Success || regexMELF.Success || regexDIOM.Success ||
               regexSOD.Success || regexSTO.Success || regexTO.Success)
            {
                result.Add(string.Join(" ", line));
            }

            else
                result.Remove(line);
        }

        // Returns the new list so it can be formatted further.
        return result;
    }

QUESTIONS

I currently have my regular expressions that sort through and divide the file up into three seperate ListBoxes.. However… I would rather have the data placed in one of the ListBoxes and then sorted/removed from that ListBox if it matches the proper regular expression.

  • How do I go about loading the .txt document into the ListBox (with every new line being a new item in the ListBox) and then going through each line in the main ListBox with regex to determine if the lines go into a different second or third ListBox or stay in the main ListBox?
  • 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-23T17:42:42+00:00Added an answer on May 23, 2026 at 5:42 pm

    Instead of multiple regexes you could just combine them into one.

    You also don’t need to call Regex.Match followed by match.Success; just call Regex.IsMatch.

    I don’t understand why you are using result.Remove(line). You never added that non-matching line, so why do you need to remove it?

    Finally, I don’t think you need to make the method specific to using List<string>. You can make it more general by specifying IEnumerable<string>.

    I’ve rewritten the first one to demonstrate the principle:

    static IEnumerable<string> findPackagePlacementOneType(IEnumerable<string> list)
    {
        return list.Where(line => Regex.IsMatch(line,
            @"^.+(RES|0402|0201|0603|0805|1206|1306|1608|3216|2551|1913|1313|2513" +
            @"|5125|2525|5619|3813|1508|6431|2512|1505|2208|1005|1010|2010|0505" +
            @"|0705|1020|1812|2225|5764|4532|1210|0816|0363|SOT)"
        ));
    }
    

    If you ever really need a new List<string>, you can just add .ToList() after a call to findPackagePlacementOneType.

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

Sidebar

Related Questions

I have a program that reads data from a file line-by-line. I would like
I have the following data (from a text file), I would like to split
I have a data file that looks like the following example. I've added '%'
Say I have a data file that I want to process; I want to
I have a file of about 30000 lines of data that I want to
I have a number of images and a CSV data file that I want
I have a PDF file, which contains data that we need to import into
I have a file log that I would like to parse and am having
I have a CSV of file of data that I can load in R
I have a file which is an XML representation of some data that is

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.