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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:20:59+00:00 2026-05-24T23:20:59+00:00

I have this code: List<string> lineList = new List<string>(); in j = 0; Dictionary<string,

  • 0

I have this code:

List<string> lineList = new List<string>();
in j = 0;
Dictionary<string, int> dictionary = new Dictionary<string, int>();

lineList = theFinalList.Select( line =>
{
     if (line.PartDescription != "")
         return line.PartDescription + " " + line.PartNumber + " " + line.TapeWidth + "\n";
     else
         return "N/A " + line.PartNumber + " " + line.TapeWidth + "\n";
})
.Where(x => !(x.Contains("FID") || x.Contains("EXCLUDE")))
.ToList();

foreach (string word in lineList)
{
    if (dictionary.ContainsKey(word))
        dictionary[word]++;
    else
        dictionary[word] = 1;
}

var ordered = from k in dictionary.Keys
              orderby dictionary[k] descending
              select k;

foreach (string key in ordered)
{
    var splitKey = key.Split(' ');
    if (!splitKey[2].Contains("8"))
    {
        sw.WriteLine(string.Format("( {0} 0 1 1 0 0 0 0 \"\" \"\" \"\" 0 0 0 0 0 0 )", j);
        j++;
    }

    sw.WriteLine(string.Format("( {0} 0 1 1 0 0 0 0 \"{1}\" \"{2}\" \"\" {3} 0 0 0 0 0 )",
                               j, splitKey[0], splitKey[1], dictionary[key]));
    j++;
}

An example of this output looks like this (assuming all of the line.TapeWidth‘s do NOT contain “8”):

( 1 0 1 1 0 0 0 0 "2125R_1.0" "136380" "" 18 0 0 0 0 0 )
( 2 0 1 1 0 0 0 0 "2125R_1.0" "128587" "" 41 0 0 0 0 0 )
( 3 0 1 1 0 0 0 0 "2125R_1.0" "138409" "" 11 0 0 0 0 0 )
( 4 0 1 1 0 0 0 0 "2125R_1.0" "110984" "" 8 0 0 0 0 0 )
( 5 0 1 1 0 0 0 0 "3216R_1.3" "114441" "" 6 0 0 0 0 0 )

HOWEVER

I would like to change it so if the !line.TapeWidth.Contains("8") then I would like to output an extra line.. Let’s say that the line that contained "138409" and "114441" both had a TapeWidth that was not equal to 8. so the NEW output would look like this:

( 1 0 1 1 0 0 0 0 "2125R_1.0" "136380" "" 18 0 0 0 0 0 )
( 2 0 1 1 0 0 0 0 "2125R_1.0" "128587" "" 41 0 0 0 0 0 )
( 3 0 1 1 0 0 0 0 "" "" "" 0 0 0 0 0 )
( 4 0 1 1 0 0 0 0 "2125R_1.0" "138409" "" 11 0 0 0 0 0 )
( 5 0 1 1 0 0 0 0 "2125R_1.0" "110984" "" 8 0 0 0 0 0 )
( 6 0 1 1 0 0 0 0 "" "" "" 0 0 0 0 0 )
( 7 0 1 1 0 0 0 0 "3216R_1.3" "114441" "" 6 0 0 0 0 0 )

So

I am trying to insert that “blank” line BEFORE the other line is printed off…

Does anyone know how I can do this?

  • 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-24T23:21:00+00:00Added an answer on May 24, 2026 at 11:21 pm

    This seems like an easy way to do it, just check for the condition before you print the line.

    foreach (string key in ordered)
    {
        var splitKey = key.Split(' ');
        if (!splitKey[1].Contains("8")) {
            sw.WriteLine("( {0} 0 1 1 0 0 0 0 "" "" "" 0 0 0 0 0 )", j);
            j++;
        }
        sw.WriteLine(
            "( {0} 0 1 1 0 0 0 0 \"{1}\" \"{2}\" \"\" {3} 0 0 0 0 0 )",
            j, splitKey[0], splitKey[1], dictionary[key]);
        j++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: List<string> lineList = new List<string>(); foreach (var line in theFinalList)
I have this code : public static List<string> MyTable = new List<string>(); dsView =
I have this code: Dim StringParts As New List(Of String)(OriginalString.Split(New Char() {\c}, StringSplitOptions.RemoveEmptyEntries)) When
I have this code Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, ~\d)) That splits lines
I have this code List<string> IDs = new List<string>(); XDocument doc = XDocument.Parse(xmlFile); var
let say I have this code Map<String, String> list = new HashMap<String, String>(); list.put(number1,
i have this code: public class Test{ arrayList<String> list = new ArrayList<String>(); String[][] temp_list;
I have this code JSONObject obj; try { obj = new JSONObject(readUrl(http://dleel.ps/ss.txt)); List<String> list
i have this code snippet private List<string> FolderOne(string Folder) { string filena; DirectoryInfo dir
I have this code: void Main() { List<Employee> employeeList; employeeList = new List<Employee> {

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.