1
/// <summary>
2
/// 翻转字符串中的单词
3
/// ex.
4
/// I am chinese. -> I ma esenihc.
5
/// </summary>
6
/// <param name="strInput"></param>
7
/// <returns></returns>
8
static string ReverseWordInString(string strInput)
9
{
10
string strMeta = ". "; //不用反的 标点符号
11
StringBuilder strReturn = new StringBuilder();
12
Stack<char> stack = new Stack<char>();
13
foreach (char c in strInput)
14
{
15
if (strMeta.IndexOf(c) != -1)
16
{
17
while (stack.Count > 0)
18
{
19
strReturn.Append((char)stack.Pop());
20
}
21
strReturn.Append(c);
22
}
23
else
24
stack.Push(c);
25
}
26
27
return strReturn.ToString();
28
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28
