判断字符串是否是由相同的字符组成

 1 /// <summary>
 2 ///  判断字符串是否是由相同的字符组成 如 aaaa全是a组成的 bbb全是b组成的 ccc全是c组成的
 3 /// </summary>
 4 /// <param name="s"></param>
 5 /// <returns></returns>
 6 public bool IsSameString(string s)
 7 {
 8     bool result = false;
 9     for (int i = 0; i < s.Length; i++)
10     {
11         string a = s[0].ToString();
12         if (a != s[i].ToString())
13         {
14             result = false;
15         }
16         else
17         {
18             result = true;
19         }
20     }
21     return result;
22 }

猜你喜欢

转载自www.cnblogs.com/xe2011/p/11494917.html