public static string GetFirstString(string stringToSub, int length) 
        
{
            Regex regex 
= new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled);
            
char[] stringChar = stringToSub.ToCharArray();
            StringBuilder sb 
= new StringBuilder();
            
int nLength = 0;
            
bool isCut=false;
            
for(int i = 0; i < stringChar.Length; i++
            
{
                
if (regex.IsMatch((stringChar[i]).ToString())) 
                
{
                    sb.Append(stringChar[i]);
                    nLength 
+= 2;
                }

                
else 
                
{
                    sb.Append(stringChar[i]);
                    nLength 
= nLength + 1;
                }


                
if (nLength > length)
                
{
                    isCut
=true;
                    
break;
                }

            }

            
if(isCut)
                
return sb.ToString()+"..";
            
else
                
return sb.ToString();
        }


http://www.yaosansi.com/blog/article.asp?id=715

posted on 2007-02-25 15:58  mbskys  阅读(93)  评论(0)    收藏  举报