Hi and good day to anyone who read this thread.

I come to meet a question to reverse a string, but it is in a different manner.
Example: "My name is Robert"(the original string) to be reversed into "Robert is name My".
Is there anyone have any idea how to achieve this.
Note: This is not my workor exercise, just for my own knowledge.

This is actually a common exercise, with well known solutions. But the neatest trick is to make two passes over the string:

  1. First Pass: Reverse all characters in the string (ie. "treboR si eman yM")
  2. Second Pass: Reverse each word in the string

Nothing fancy, just super basic string handling, and you have an elegant solution. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.