//
        
//判断此字符是否为中文
        
//
        private bool Check_Chinese(char tmpchar)
        {
            
bool bResult = false;
            
int i = (int)tmpchar;

            
if (i < 0x4E00 || i > 0x9fa5)
            {
                
// return false;
            }
            
else
            {
                bResult 
= true;
            }
            
return bResult;
        }

        
//
        
//取得字符串的长度,一个中文=1,一个字母=0.5
        
//
        public double Get_Count_From_String(string tmpStr)
        {
            
double fl = 0;
            
foreach (char c in tmpStr)
            {
                
if (Check_Chinese(c) == true)
                {
                    fl 
= fl + 1;
                }
                
else
                {
                    fl 
= fl + 0.5;
                }
            }

            
return fl;
        }

        
//
        
//截取对应长度的字符串
        
//
        public string Get_LenString(string tmpStr,int tmpLen)
        {
            
double fl = 0;
            
string sResult = "";
            
if (tmpStr.Length >= tmpLen)
            {
                
foreach (char c in tmpStr)
                {
                    sResult 
= sResult + c;
                    
if (Check_Chinese(c) == true)
                    {
                        fl 
= fl + 1;
                    }
                    
else
                    {
                        fl 
= fl + 0.5;
                    }
                    
if (fl >= 4)
                    {
                        
return sResult;
                    }
                }
            }

            
return "";
        }

posted on 2008-09-17 00:51  晃晃悠悠  阅读(427)  评论(0)    收藏  举报