elmo monster

elmo monster

  • NA
  • 1
  • 14.2k

C# program to reverse each word of a sentence separately?

Apr 12 2014 1:19 PM
a C# program to reverses each word in a sentence except these punctuation marks (? ! . ,)

example: (input) this is john, who are you?

(output) sith si nhon, ohw era uoy?
_______________________________________...
here's my code which reverses punctuation marks too and removes the space character in the output.. :,(

string str = Console.ReadLine();
string strrev = "";

foreach (var word in str.Split(' '))
{
string temp = "";
foreach (var ch in word.ToCharArray())
{
temp = ch + temp;
}
strrev = strrev + temp + "";
}
Console.WriteLine(strrev);
Console.ReadLine();

Answers (4)