日期:2010-07-08  浏览次数:20537 次

  最近做一个论坛,发现标题中如果有连续的字母或其他特殊字符,比如¥、$、。、,、~、!、、、?、*、…,这样将导致不能自动换行,解决的办法是使用如下方法,当标题中连续的字母或特殊字符达到一定的长度时,可以使用指定的tag来强制换行。

              public static string FormatStr(string str, int len, string tag)

              {

                     char[] arrChar = new char[10]{ '。',',','~','!','、','?','*','…','¥','$'};

                     StringBuilder sb = new StringBuilder();

                     int i = 0;

                     foreach (char Char in str)

                     {

                            bool bIsContain = false;

                            for(int j = 0; j < arrChar.Length; j++)

                            {

                                   if(Char.CompareTo(arrChar[j]) == 0)

                                   {

                                          bIsContain = true;

                                          break;

                                   }

                            }

                            if ((int)Char <= 127 || bIsContain)

                                   i += 1;

                            else

                                   i = 0;

       &nb