Reverse a string but not words (Rate my solution)
So i wrote up a quick program to reverse a string but not the actual words, So basically if I have input such as
"how are you" , after passing that string through my method itll become "you are how", Here is my code for doing so, please give me your opinions on my algorithm.
Code:
private static string ReverseString(string stringToReverse)
{
char[] stringArray = stringToReverse.ToCharArray();
string reversedString = "";
string tmpCopy = "";
const int END_OF_STRING = 1;
const char SPACE=' ';
const string CLEAR_STRING = "";
for (int i = stringArray.Length; i > 0; i--)
{
if (stringArray[i - 1] != SPACE)
{
tmpCopy += stringArray[i - 1];
}
if (stringArray[i - 1] == SPACE || i == END_OF_STRING)
{
for (int j = tmpCopy.Length; j > 0; j--)
{
reversedString += tmpCopy[j - 1];
}
if (stringArray[i - 1] == SPACE)
{
reversedString += SPACE;
}
tmpCopy =CLEAR_STRING;
}
}
return reversedString;
}