Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

First off, I am new to coding and this is my first official application

I need to write an application for a client where you enter data into to Text boxes.

The data then needs to be compared in the background and results displayed below.

Example
ie. Box A contains: 1 2 3 4
Box B contains: 2 3 4 5

The results should be:
Box A: 5
Box B: 1

The reason for this application is that the users will paste a list of Order Numbers from two sources. These two lists will be compared and results shown. Which means that the data pasted needs to be entered and separated (so that each Order Number has it's own value in the list).

I have gotten the displaying of data working. and I think the data splitting is working. What I need to do now is compare the data and confirm that the data is being split into separate entries.

here is the code I'm using at the moment:

C#
//Left Collection Entries
           List<string> leftCollection = new List<string>();
           leftCollection.Add(txtLeftCollection.Text);

           txtLeftResult.Text = Convert.ToString(leftCollection);
           txtLeftResult.Text = "";
           txtLeftResult.Text += leftCollection[0];

           string splitLeft = Convert.ToString(leftCollection);

           string[] wordsL = splitLeft.Split('\n');
           foreach (string word in wordsL)
           {
               Console.WriteLine(word);
           }

           //Right Collection Entries
           List<string> rightCollection = new List<string>();
           rightCollection.Add(txtRightCollection.Text);

           txtRightResult.Text = Convert.ToString(rightCollection);
           txtRightResult.Text = "";
           txtRightResult.Text += rightCollection[0];


           string splitRight = Convert.ToString(leftCollection);

           string[] wordsR = splitRight.Split('\n');
           foreach (string word in wordsR)
           {
               Console.WriteLine(word);
           }


Can someone please help me on this.

Thank you in advance.

Corne
Posted
Updated 18-Oct-12 2:29am
v2

 
Share this answer
 
Comments
Big-C8701 18-Oct-12 7:07am    
Thanks you for the reply.

As I said im still learning and at this point i do not know how to incorporate that into my code. I forgot to mention this is a windows application that i need to write.

Thanks again
Try this

C#
namespace ConsoleApplication17
{
    class Program
    {
        static void Main()
        {
            string s1 = "1 2 3 4";
            string s2 = "2 3 4 5";



            string[] arrayOne = s1.Split(' ');
            string[] arrayTwo= s2.Split(' ');
            string Left=string.Empty;
            string Right=string.Empty;
            foreach (string word in arrayOne)
            {
                if (!(arrayTwo.Contains(word)))
                {
                    if (Left == string.Empty)
                        Left = word;
                    else
                        Left = Left + " " + word;
                }
            }
            foreach (string word in arrayTwo)
            {
                if (!(arrayOne.Contains(word)))
                {
                    if (Right == string.Empty)
                        Right = word;
                    else
                        Right = Right + " " + word;
                }
            }

            Console.WriteLine(Left);
            Console.WriteLine(Right);
            Console.Read();
        }

    }
}
 
Share this answer
 
Comments
Big-C8701 18-Oct-12 15:40pm    
Thank you Santosh Kumar. I did the following:

{
//Clear previous Results
txtLeftResult.Text = "";
txtRightResult.Text = "";

//Left Collection Entries
List<string> leftCollection = new List<string>();
leftCollection.AddRange(txtLeftCollection.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None));
//Right Collection Entries
List<string> rightCollection = new List<string>();
rightCollection.AddRange(txtRightCollection.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None));

//Loop through left collection
foreach (string row in leftCollection)
{
if (!rightCollection.Contains(row))
{
txtLeftResult.Text = txtLeftResult.Text + "\r\n" + row;
}
}
if (txtLeftResult.Text.Length > 0)
{
txtLeftResult.Text = txtLeftResult.Text.Remove(0, 2);
}

//Loop through Right collection
foreach (string row in rightCollection)
{
if (!leftCollection.Contains(row))
{
txtRightResult.Text = txtRightResult.Text + "\r\n" + row;
}
}
if (txtRightResult.Text.Length > 0)
{
txtRightResult.Text = txtRightResult.Text.Remove(0, 2);
}



}
Thank you for the help

here is my solution

C#
{
            //Clear previous Results
            txtLeftResult.Text = "";
            txtRightResult.Text = "";

            //Left Collection Entries
            List<string> leftCollection = new List<string>();
            leftCollection.AddRange(txtLeftCollection.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None));            
            //Right Collection Entries
            List<string> rightCollection = new List<string>();
            rightCollection.AddRange(txtRightCollection.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None));

            //Loop through left collection
            foreach (string row in leftCollection)
            {
                if (!rightCollection.Contains(row))
                {
                    txtLeftResult.Text = txtLeftResult.Text + "\r\n" + row;
                }
            }
            if (txtLeftResult.Text.Length > 0)
            {
               txtLeftResult.Text = txtLeftResult.Text.Remove(0, 2);
            }

            //Loop through Right collection
            foreach (string row in rightCollection)
            {
                if (!leftCollection.Contains(row))
                {
                    txtRightResult.Text = txtRightResult.Text + "\r\n" + row;
                }
            }
            if (txtRightResult.Text.Length > 0)
            {
                txtRightResult.Text = txtRightResult.Text.Remove(0, 2);
            }


            
        }</string></string></string></string>
 
Share this answer
 
it can be done easily with Linq
C#
string[] Lbox=LeftTextbox.Text.Split(' ');// box A
string[] Rbox=RightTextbox.Text.Split(' ');//box B
var c = Rbox.Except(Lbox);
Console.Write("Box A : ");
foreach(string i in c)
Console.Write(" "+i);

var c = Lbox.Except(Rbox);
Console.Write("Box B : ");
foreach(string i in c)
Console.Write(" "+i);
 
Share this answer
 
Comments
Big-C8701 19-Oct-12 1:45am    
Thank you Silent Gaurdian,

For the application I had to do it without Linq. The application is for a client and friend who is helping me study to be a Developer. He is paying me for the application but he is also teaching me. His instructions were to develop this app without using Linq. just using C# and Lists.

Thank you once again for the assistance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900