1/// <summary>
2 /// 去除字符串中相邻两个字符的重复
3 ///
4 /// exp.
5 /// abb -> ab
6 /// abbccaabbcc -> abcabc
7 /// aaabbb -> ab
8 /// </summary>
9 /// <param name="strInput"></param>
10 /// <returns></returns>
11 static string GetStringOfSingleChar(string strInput)
12 {
13 if (strInput == null)
14 throw new Exception("String cannot be null.");
15
16 int Length = 0;
17 if ((Length = strInput.Length) < 2) return strInput;
18 char[] strArray = strInput.ToCharArray();
19
20 int count = 0;
21 for (int i = 1; i < Length; i++)
22 {
23 if (strArray[i] != strArray[i - 1]) continue;
24
25 char cTemp = strArray[i];
26 for (int j = i; j < Length - 1; j++)
27 strArray[j] = strArray[j + 1];
28 strArray[Length - 1] = cTemp;
29
30 if (i + count >= Length) break;
31 i--;
32 count++;
33 }
34
35 return new string(strArray , 0 , Length - count);
36 }
2 /// 去除字符串中相邻两个字符的重复
3 ///
4 /// exp.
5 /// abb -> ab
6 /// abbccaabbcc -> abcabc
7 /// aaabbb -> ab
8 /// </summary>
9 /// <param name="strInput"></param>
10 /// <returns></returns>
11 static string GetStringOfSingleChar(string strInput)
12 {
13 if (strInput == null)
14 throw new Exception("String cannot be null.");
15
16 int Length = 0;
17 if ((Length = strInput.Length) < 2) return strInput;
18 char[] strArray = strInput.ToCharArray();
19
20 int count = 0;
21 for (int i = 1; i < Length; i++)
22 {
23 if (strArray[i] != strArray[i - 1]) continue;
24
25 char cTemp = strArray[i];
26 for (int j = i; j < Length - 1; j++)
27 strArray[j] = strArray[j + 1];
28 strArray[Length - 1] = cTemp;
29
30 if (i + count >= Length) break;
31 i--;
32 count++;
33 }
34
35 return new string(strArray , 0 , Length - count);
36 }