Click here to Skip to main content
15,867,568 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to remove characters from string value Pin
Richard MacCutchan23-Jan-11 8:22
mveRichard MacCutchan23-Jan-11 8:22 
JokeRe: How to remove characters from string value Pin
Not Active23-Jan-11 10:19
mentorNot Active23-Jan-11 10:19 
GeneralRe: How to remove characters from string value Pin
Abhinav S23-Jan-11 17:30
Abhinav S23-Jan-11 17:30 
AnswerRe: How to remove characters from string value Pin
Paladin200024-Jan-11 3:54
Paladin200024-Jan-11 3:54 
QuestionBuild and use user control (vs 2010) Pin
ladoota22-Jan-11 20:13
ladoota22-Jan-11 20:13 
AnswerRe: Build and use user control (vs 2010) Pin
Richard MacCutchan22-Jan-11 21:38
mveRichard MacCutchan22-Jan-11 21:38 
AnswerRe: Build and use user control (vs 2010) Pin
RaviRanjanKr23-Jan-11 17:36
professionalRaviRanjanKr23-Jan-11 17:36 
QuestionRemoving duplicates / extracting unique vals from String array Pin
csrss22-Jan-11 1:25
csrss22-Jan-11 1:25 
Alright, so i got an array like this:

String[] Arr = { "A, B, C", "B, A, C", "C, A", "B, C, A", "D, A, N, V", "N, W, B, A"};


I am trying to extract unique values / remove duplicates from this array, so in the end the output will be like:

A, B, C, D, N, V, W

Now here is my function:

public static String[] Extract(String[] List)
        {
            String[] Output = null;
            String Symbols = String.Empty;
            String SymbolsHere = String.Empty;

            foreach (String Text in List)
            {
                if (Text.Contains(","))
                {
                    String[] Vals = Text.Split(new char[] { ',' });
                    foreach (String Val in Vals)
                    {
                        if (SymbolsHere.IndexOf(Val) == -1)
                        {
                       //     MessageBox.Show(SymbolsHere, Val);
                            SymbolsHere += Val + " ";
                            Symbols += Val + ", ";
                        }
                    }
                }
                else
                {
                    if (SymbolsHere.IndexOf(Text) == -1)
                    {
                        Symbols += Text + ", ";
                        SymbolsHere += Text + " ";
                    }
                }
            }
     //       MessageBox.Show(SymbolsHere);
            MessageBox.Show(Symbols);
            return Output;
        }


Well, this almost works, but...
Last messagebox shows "A, B, C, A, D, N, V, W" instead of "A, B, C, D, N, V, W", so as you can see, one extra "A" char gets into output and i got no idea why Confused | :confused:

Take a look at this part:
if (SymbolsHere.IndexOf(Val) == -1)
{
       MessageBox.Show(SymbolsHere, Val);
       SymbolsHere += Val + " ";
       Symbols += Val + ", ";
}

So, like, if symbol has not been found in already collected symbols container, show
symbols container itself and a new symbol. But, at this moment app pops a msgbox with collection of syms: A B C and new symbol,
which is not found in our collection: A.
Its like, absurd - A is already thereConfused | :confused:
What is wrong with this code? Thanks
011011010110000101100011011010000110100101101110
0110010101110011

AnswerRe: Removing duplicates / extracting unique vals from String array Pin
Luc Pattyn22-Jan-11 1:54
sitebuilderLuc Pattyn22-Jan-11 1:54 
GeneralRe: Removing duplicates / extracting unique vals from String array Pin
csrss22-Jan-11 2:07
csrss22-Jan-11 2:07 
AnswerRe: Removing duplicates / extracting unique vals from String array Pin
dan!sh 22-Jan-11 2:04
professional dan!sh 22-Jan-11 2:04 
GeneralRe: Removing duplicates / extracting unique vals from String array Pin
csrss22-Jan-11 2:09
csrss22-Jan-11 2:09 
AnswerRe: Removing duplicates / extracting unique vals from String array Pin
PIEBALDconsult22-Jan-11 3:30
mvePIEBALDconsult22-Jan-11 3:30 
AnswerRe: Removing duplicates / extracting unique vals from String array [modified] Pin
DaveyM6922-Jan-11 5:47
professionalDaveyM6922-Jan-11 5:47 
GeneralRe: Removing duplicates / extracting unique vals from String array Pin
Mirko198024-Jan-11 22:11
Mirko198024-Jan-11 22:11 
QuestionPlease Check Pin
M Riaz Bashir21-Jan-11 23:25
M Riaz Bashir21-Jan-11 23:25 
AnswerRe: Please Check Pin
OriginalGriff21-Jan-11 23:42
mveOriginalGriff21-Jan-11 23:42 
GeneralRe: Please Check Pin
M Riaz Bashir21-Jan-11 23:48
M Riaz Bashir21-Jan-11 23:48 
GeneralRe: Please Check Pin
Henry Minute22-Jan-11 4:00
Henry Minute22-Jan-11 4:00 
AnswerRe: Please Check Pin
_Erik_24-Jan-11 3:43
_Erik_24-Jan-11 3:43 
Questioni want to solve this Pin
Nabawoka21-Jan-11 22:21
Nabawoka21-Jan-11 22:21 
AnswerRe: i want to solve this Pin
Richard MacCutchan21-Jan-11 22:35
mveRichard MacCutchan21-Jan-11 22:35 
GeneralRe: i want to solve this Pin
Nabawoka21-Jan-11 22:39
Nabawoka21-Jan-11 22:39 
AnswerRe: i want to solve this Pin
Nabawoka21-Jan-11 22:55
Nabawoka21-Jan-11 22:55 
GeneralRe: i want to solve this Pin
Estys21-Jan-11 23:00
Estys21-Jan-11 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.