I have to Replace the characters of input string at odd positions by next character in alphabet.
string input = Console.ReadLine();
char k = input.ToCharArray().Select((val,i) =>(i%2==0) && (char)((int)val + 1)).ToArray();
string output=new string(k)
You are almost there, need to do little more to achieve the target. You have to notice the Following things and make those changes:
i%2==0determines whether the character need to be replaced or not, so you have to apply conditional operator(
(char)((int)x + 1). this will first evaluates
(int)xand gives the integer value of that particular character. then add
1to it then get the corresponding character.
String.Jointo make the output string from the character array
You can try something like this:
string input = "ABCD"; char k = input.Select((x, i) => i % 2 == 0 ? (char)((int)x + 1) : x).ToArray(); string output = String.Join("",k);
Note the following things as well:
Zthe next value from the ASCII table will be assigned, that will be
Athen you have to apply conditions for that.