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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:07+00:00 2026-05-23T20:10:07+00:00

Here is the text file that I am loading in: ORIGINAL FILE 10 BARE

  • 0

Here is the text file that I am loading in:

ORIGINAL FILE

10 BARE PCB
20 T C40
B C5, C45, C48
30 B C25
40 B C17, C18
50 B C15
60 T C20, C23,
B C6, C7, C8, C9, C10, C11, C12,
C31, C32, C33, C34, C35, C36,
C37, C38, C39
70 T C16, C21, C22, C24, C41, C42
B C3, C19, C43, C44, C47
80 T C13, C14
B C1, C2
90 B C26, C27, C28, C29, C30
100 T R65
110 T R35
120 T R34
130 T R33
140 T R21, R22, R29, R30
150 B R28, R31, R32, R37
160 T R17, R19, R26, R47, R50, R51,
R53, R57, R58, R59
B R18, R25, R42, R48, R49, R52,
R54, R55, R56, R60
170 T R23
B R10, R43
180 T R8, R9
190 T R13, R14, R15, R61, R62, R63,
R64
200 T R27, R38, R39, R40, R41
B R2, R3, R11, R44, R45, R46
210 B R1
220 T C4
230 T D1
240 T U1
250 B U10
270 B U6
280 B U5
290 B U4
300 T U2
310 B U7
320 B U8
330 T U9
340 B L2, L3
350 B L8, L9
360 B L1, L4, L5, L6, L7, L10
370 B J1, J2
380 B J3
390 B X1
400 T X2
410 B J4
420 B J5
422 B U3
2000 T TRACKING LABEL
423 ADHESIVE
424 ACCELERATOR
425 ADHESIVE

And this is what I have the file being formatted to:

FORMATTED FILE

0010 BARE PCB
0020 C40
0020A C5, C45, C48
0030A C25
0040A C17, C18
0050A C15
0060 C20, C23,
0060A C6, C7, C8, C9, C10, C11, C12,C31, C32, C33, C34, C35, C36,C37, C38, C39
0070 C16, C21, C22, C24, C41, C42
0070A C3, C19, C43, C44, C47
0080 C13, C14
0080A C1, C2
0090A C26, C27, C28, C29, C30
0100 R65
0110 R35
0120 R34
0130 R33
0140 R21, R22, R29, R30
0150A R28, R31, R32, R37
0160 R17, R19, R26, R47, R50, R51,R53, R57, R58, R59
0160A R18, R25, R42, R48, R49, R52,R54, R55, R56, R60
0170 R23
0170A R10, R43
0180 R8, R9
0190 R13, R14, R15, R61, R62, R63,R64
0200 R27, R38, R39, R40, R41
0200A R2, R3, R11, R44, R45, R46
0210A R1
0220 C4
0230 D1
0240 U1
0250A U10
0270A U6
0280A U5
0290A U4
0300 U2
0310A U7
0320A U8
0330 U9
0340A L2, L3
0350A L8, L9
0360A L1, L4, L5, L6, L7, L10
0370A J1, J2
0380A J3
0390A X1
0400 X2
0410A J4
0420A J5
0422A U3
2000 TRACKING LABEL
0423 ADHESIVE
0424 ACCELERATOR
0425 ADHESIVE

HOWEVER

If you look closely in the formatted file there is a few spots where there is no space after one of the commas (C12,C31 & C36,C37 & R51,R53 & R52,R54 & R63,R64). I would like there to be a space in between there..

CODE

    private void openRefsFormatHelper()
    {
        try
        {
            // Resets the formatted refs text.
            formattedRefsTextRichTextBox.ResetText();

            // Reads the lines in the file to format.
            var reader = File.OpenText(openRefs.FileName);

            // Creates a list for the lines to be stored in.
            var list = new List<string>();

            // Adds each line in the file to the list.
            while (true)
            {
                var line = reader.ReadLine();
                if (line == null)
                    break;
                list.Add(line);
            }

            // Handles all of the requirements for the reference text.
            list = fourDigitRequirement(list);
            list = concatRequirement(list);
            list = startsWithBRequirement(list);
            list = elementIsBRequirement(list);
            list = removeTRequirement(list);

            // Prints the formatted refs to the richtextbox.
            foreach (var line in list)
                formattedRefsTextRichTextBox.AppendText(line + "\n");
        }

        // Catches an exception if the file could not be formatted.
        catch (Exception)
        {
            MessageBox.Show("There was a problem formatting the 'Refs File'.", "Refs File Format Error",
                MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }

    static List<string> elementIsBRequirement(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)
        {
            // Splits each line into 'parts'
            var parts = line.Split(' ');

            // Checks if the second 'part' array is "B"
            if (parts[1].Equals("B"))
            {
                // If it is "B", replace with "A" and add to the new list "result"
                parts[0] += "A";
                parts[1] = string.Empty;

                result.Add(string.Join(" ", parts));
            }

            // Otherwise keep the line how it is.
            else
                result.Add(line);
        }

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

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

        // Checks if the line begins with "B"
        foreach (var line in list)
        {
            // Splits each line into 'parts'
            var parts = line.Split(' ');

            // Checks if the first 'part' array is "B"
            if (parts[0].Equals("B"))
            {
                // If it is "B", copy the previous line down and add "A" where "B" was at
                // and add to the new list "result".
                parts[0] = string.Empty;
                result.Add(list[i - 1].Split(' ')[0] + "A" + string.Join(" ", parts));
            }

            // Otherwise keep the line how it is.
            else
                result.Add(line);

            i++;
        }

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

    static List<string> concatRequirement(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)
        {
            // Splits each line into 'parts'
            var parts = line.Split(' ');
            int test;

            // Concats everything together
            if (int.TryParse(parts[0], out test) || parts[0].Equals("B"))
                result.Add(line);

            // Otherwise result - 1
            else
                result[result.Count - 1] += line;
        }

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

    static List<string> removeTRequirement(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)
        {
            // Splits each line into 'parts'
            var parts = line.Split(' ');

            // Checks if the second 'part' array is "T", if it is, remove "T"
            if (parts[1].Equals("T"))
                parts[1] = string.Empty;

            // Add the new string to the result.
            result.Add(string.Join(" ", parts).Replace("  ", " "));
        }

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

    static List<string> fourDigitRequirement(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)
        {
            // Splits each line into 'parts'
            var parts = line.Split(' ');
            int test;

            // Checks if the array[0] (digits) is the proper length.
            if (int.TryParse(parts[0], out test))
            {
                // If it is not a length of 4 digits, add "O" to the front until it is.
                parts[0] = parts[0].PadLeft(4, '0');

                // Add the new string to the result list.
                result.Add(string.Join(" ", parts));
            }

            // Otherwise keep the line how it is.
            else
                result.Add(line);
        }

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

QUESTION:
– How do I get that space in there?

  • 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-23T20:10:08+00:00Added an answer on May 23, 2026 at 8:10 pm

    In concatRequirement, you can change:

                result[result.Count - 1] += line;
    

    to

                result[result.Count - 1] += " " + line;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some original text: here is some text that has a
Here is a simple program to output to a text file: #include <iostream> #include
Please take a look here: alt text http://img16.imageshack.us/img16/2810/errrp.jpg Why i got that error when
I have application reads in data from text file. Recently I realized that I
I have a simple Java program that reads in a text file, splits it
I have a text file that I am pulling from my SD card which
I have a text file that is being written to as part of a
I have an HTML file that I am loading into a JTextPane which contains
I have an external xml file that I am loading in my views.py file
Can check out here alt text http://51hired.com/static/problem.bmp

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.