首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

字符串 排序的有关问题 急

2012-02-01 
字符串 排序的问题 急~~~在线等~~问一下我要将一句话排序比如“ILOVETHEGREATWALL”转换成“GREADWALLTHELOVE

字符串 排序的问题 急~~~在线等~~
问一下   我要将一句话排序  
比如“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 ";
}

热点排行