Senator Guerra Souty original series calendar,replica hublot blue steel peach pointer collocation of rolex replica Rome digital scale, track type minute replica watches scale shows that the classical model is swiss replica watches incomparable, wearing elegant dress highlights.
mr-ponna.com

 

YOU ARE HERE: HOME Questions Write code to print the words in reverse in given string without using any inbuilt functions Not the



Code to print the words in reverse in given string

View(s): 30259

Write code to print the words in reverse in given string without using any inbuilt functions. Not the entire string, only words in the given string should reverse.

Answer 1)
Here is code snippet. 

static void Main(string[] args)
{
string text = "This is Mr. Ponna"; //Input string is "This is Mr. Ponna"
Console.WriteLine(PrintWordsInReverse(text)); //output: "sihT si .rM annoP"
}

// This method will print the words in reverse in given string
static string PrintWordsInReverse(string str)
{
string revWord = string.Empty;
string finalSentance = string.Empty;
for (int i = 0; i < str.Length; i++)
{
if (str[i] != ' ')
{
revWord = str[i] + revWord;
}
else
{
revWord = revWord +
' ';
finalSentance = finalSentance + revWord;
revWord =
string.Empty;
}
}

if (revWord != string.Empty)
finalSentance = finalSentance + revWord;

return
finalSentance;
}

  Asked in:  MindTree   Expertise Level:  Intermediate
  Last updated on Sunday, 22 May 2011
2/5 stars (15 vote(s))

Register Login Ask Us Write to Us Help