Well, here is the LINQ solution:
var reversedWords = string.Join(" ",
str.Split(' ')
.Select(x => new String(x.Reverse().ToArray())));
If you are using .NET 3.5, you also need to convert the inverse sequence to an array:
var reversedWords = string.Join(" ",
str.Split(' ')
.Select(x => new String(x.Reverse().ToArray()))
.ToArray());
In other words:
- Divide by spaces
- For each word, create a new word, treating the input as a sequence of characters, cancel this sequence, turn the result into an array, and then call the constructor
string(char[]) ToArray() , .NET 4string.Join , .
, . :
public static string ReverseText(this string text)
{
char[] chars = text.ToCharArray();
Array.Reverse(chars);
return new string(chars);
}
, - "" - - , .. UTF-16 . , , .