Wednesday, March 16, 2011

Display unique characters only in a textbox

If I give the input from Text Box like

AaBbcdCDEb

the output should be

ABCDE or abcde

only unique characters should be there, no repeated characters.

How do I do this?

From stackoverflow
  • Use the Distinct extention method on the array of characters then recombine them into a string.

    new string("AaBbcdCDEb".ToLower().Distinct().ToArray());
    
    Masuma Aktar : can u send me code........pls i am beginner practicing
    Shahin : He did, didn't he?
    Daok : This will only work IF he is with framework3, not 2.0...
    Lee Richardson : Beautiful. I love LINQ.
  • foreach char in textbox, if textbox/new string contains char then return, else add to new string?

    Masuma Aktar : Sir i want to give dynamic input at run time from TextBox.....if the the input is AABBCCDD and if i click one Button the result should be displayed in another TextBox.....Result should be only ABCD.......sir pls send me the entire code.
    Drejc : FedEx, TNT, UPS what's you favourite?
  • string input = "AABBCCDD";
    string output = string.empty; 
    foreach(char c in input)
        if (!output.Contains(c))
            output += c;
    
    Masuma Aktar : Thank you sir its working fine......but its working only for either uppercase or lower case not both i mean if i give input "AAABBCCDDaabbccdd" the output is coming "ABCDabcd" but output should be either"ABCD" only or "abcd"only but not both.....pls send me sir.
    ctacke : Do your own work or go into another field.

0 comments:

Post a Comment