C#截取字符串前几位.区分中英文

    public string getStr(string strInput, int intLen)
    {
        strInput 
= strInput.Trim();
        
byte[] myByte = System.Text.Encoding.Default.GetBytes(strInput);
        Response.Write(
"getStr Function is::" + myByte.Length.ToString());
        
if (myByte.Length > intLen)
        {
            
//截取操作
            string resultStr = "";
            
for (int i = 0; i < strInput.Length; i++)
            {
                
byte[] tempByte = System.Text.Encoding.Default.GetBytes(resultStr);
                
if (tempByte.Length < intLen)
                {
                    resultStr 
+= strInput.Substring(i, 1);
                }
                
else
                {
                    
break;
                }
            }
            
return resultStr + "...";
        }
        
else
        {
            
return strInput;
        }
    }
原文地址:https://www.cnblogs.com/yeagen/p/1357379.html