Skip to content

Predetermined characters

Asked Sep 7, 2013, 12:56 AM EDTSolved
Share
LinkedInX
I wish to know is there any code in C# to pick up predetermined characters from random input.

Suppose we say predetermined characters are "Address"

Random console input is 3545325Adggfdgdfgd3!@$@@#rsfssefas&*acs.

Program will realise there are A, d, d, r, e, s, and s letters in it and pick up and return it.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    ✓ Accepted answer0
    Hi Maha,

    How about doing it this way:
    -------------------------------------------------------------------
    C#
     string inputStr = "3545325Adggfdgdfgd3!@$@@#rsfssefas&*acs";
               string checkStr = "Address";
               List<char> FoundChars = new List<char>();
                 if (!string.IsNullOrEmpty(inputStr))
               {
                   foreach (char c in checkStr)
                   {
                       if (inputStr.IndexOf(c) > -1)
                       {
                           FoundChars.Add(c);
                           continue;
                       }             
                  }
                     foreach (char c in FoundChars)
                   {
                       Console.Write(c);
                   }
     
               }
    -------------------------------------------------------------------------
    
    Hope it helps :)
    0
  • 0
    I did a small modification in your program so it fulfills my expectation. Thank you for your help.

    Modification is character must be the i/p from the keyboard. Which is
    string inputStr = Console.ReadLine();
    0
  • 2 short replies
    • 0
      Thank you for your help.
      0
    • Sunny  Sharma
      0
      so what output do you expect?
      0