日期:2014-05-19  浏览次数:20887 次

字符串 排序的问题 急~~~在线等~~
问一下   我要将一句话排序  
比如“I   LOVE   THE   GREATWALL”转换成“GREADWALL   THE   LOVE   I”
用C#应该怎么做?

------解决方案--------------------
static void Main(string[] args)
{
// Define a test string.
string text = "The quick brown fox jumped over the lazy dog. ";
OrderofWord ow = new OrderofWord();
ow.OrderTheWord(text);
Console.Read();
}

//排序方法
public string OrderTheWord(string text)
{
// Define a regular expression for repeated words.
Regex rx = new Regex(@ "\b(? <word> \w+)\b ",
RegexOptions.Compiled | RegexOptions.IgnoreCase);

// Find matches.
MatchCollection matches = rx.Matches(text);

// Report on each match.
string word = " ";
foreach (Match match in matches)
{
word = " " + match.Groups[ "word "].Value + word;
int index = match.Index;
Console.WriteLine( "{0} repeated at position {1} ", word, index);
}
return "word ";
}