0

Hi guys.. I don't know how to do this, the result would be like this,

you input then the repeated numbers would appear once only..

like this Screenshot

Attachments sample_lng.jpg 12.7 KB
3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by wil0022
Featured Replies
1

Show us the code you got so far. We will be most happy to help you with your problems.

Comments
Indeed
0

do you need to worry with the order of the numbers? if not you could easily work with the numbers as strings. split them into an array by the space, create a destination and list and loop through them, if the dest list doesn't already contain the value, then add it.

pretty simple.

0

this will not double output the number if I use string?

can you give me an example? sorry im a newbie in C#

@ddanbe

sorry i dont have a code that have made my self..

I tried to make one.. but it seems.. it is all wrong.. sorry...

Edited by wil0022: n/a

0

please keep in mind that we are not apt to giving out free code. but this is so simple it only took me 3 minutes to write it.

private string removedDup(string s)
        {

            string[] allnumbers =s.Split(new char[] { ' ' });

            List<string> cutnumbers = new List<string>();

            foreach (string num in allnumbers)
            {
                if (!cutnumbers.Contains(num))
                {
                    cutnumbers.Add(num);
                }
            }

            string final = "";

            foreach(string ss in cutnumbers)
            {
                final += ss + " ";
            }

            return final.Trim();


        }

just a simple method, pass to it a string with numbers separated by spaces, and it returns a string with numbers separated by spaces. That simple.

0

please keep in mind that we are not apt to giving out free code. but this is so simple it only took me 3 minutes to write it.

private string removedDup(string s)
        {

            string[] allnumbers =s.Split(new char[] { ' ' });

            List<string> cutnumbers = new List<string>();

            foreach (string num in allnumbers)
            {
                if (!cutnumbers.Contains(num))
                {
                    cutnumbers.Add(num);
                }
            }

            string final = "";

            foreach(string ss in cutnumbers)
            {
                final += ss + " ";
            }

            return final.Trim();


        }

just a simple method, pass to it a string with numbers separated by spaces, and it returns a string with numbers separated by spaces. That simple.

thanks... I'll try this one, but could I make a my own without creating "private string removedDup(string s)" like this? thanks a lot..

0

thanks... I'll try this one, but could I make a my own without creating "private string removedDup(string s)" like this? thanks a lot..

if you didn't want it to be a method, you could easily just remove that part, start with a sting called s and the final product here is declared as final.

0

sorry i dont have a code that have made my self..

I tried to make one.. but it seems.. it is all wrong.. sorry...

That is just the code we like to see!
I have already posted code here of wich I am not proud, but the guys and girls here explained it and I learned from it!
Do the same!
Unless you are sitting there, with an attitude of: I have to take up a C# course. I'm not interested. The teacher sucks. Just waiting until DANIWEB gives an answer... Diamonddrake whom I appreciate very much, is a very kind person.

0

That is just the code we like to see!
I have already posted code here of wich I am not proud, but the guys and girls here explained it and I learned from it!
Do the same!
Unless you are sitting there, with an attitude of: I have to take up a C# course. I'm not interested. The teacher sucks. Just waiting until DANIWEB gives an answer... Diamonddrake whom I appreciate very much, is a very kind person.

that's why im thankful that Diamonddrake visited my thread.. my tomorrow morning i could show you some code... it's so late now guys.. thanks for helping me out.. maybe tomorrow i could show you the code.. even it is all wrong... thanks... gudnyt :D

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.