0

I am writing a program where I have a set of number 123456789 and words ABCDEFGHI. Now if a user enters any number its equivalent letter should show up in the result. Can someone guide me on how to approach this question.

For EX: user entry of 1352 should result in ACEB

  • This might help you get started: https://stackoverflow.com/questions/2416894/how-to-return-the-character-which-is-at-the-index – Swamy Jun 13 '18 at 02:11

1 Answers1

4

Welcome here, your question is too 'easy' to become a question. And at lease you should show up what you have done.

But I will give you a shot.

I have wrote simple method for solve your question.

Sandbox to run this online

//Your code goes here
Console.WriteLine("Hello, world!");
//predifine your sets
var inputSet = new List<char> {'1','2','3','4','5','6','7','8','9','0'};
var outputSet = new List<char>{'A','B','C','D','E','F','G','H','I','J'};
//lets parse
Console.WriteLine(new string("1352".Select(x=>outputSet[inputSet.IndexOf(x)]).ToArray()));
Console.WriteLine(new string("199466856".Select(x=>outputSet[inputSet.IndexOf(x)]).ToArray()));
Console.WriteLine(new string("111222333444".Select(x=>outputSet[inputSet.IndexOf(x)]).ToArray()));

Result:

Hello, world!

ACEB

AIIDFFHEF

AAABBBCCCDDD

Edit:

Explain how it works.

"1352".Select(x) To select chars one by one in the string and store in x.

inputSet.IndexOf(x) To find position of x in inputSet

outputSet[int] To get value by given position from found position in inputSet recenly

new string(char array) Instantiate a new string by given char array.

robe007
  • 3,523
  • 4
  • 33
  • 59
nyconing
  • 1,092
  • 1
  • 10
  • 33