请问这些代码有什么不妥的地方吗?使用过程中有时会出错,提示
索引和长度必须引用该字符串内的位置。
参数名: length 
异常详细信息: System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。
参数名: length源错误: 
行 221:        str = str.Replace("<br />", "\n");
行 222:        str = str.Replace("<br/>", "\n");
行 223:        string temp = str.Substring(0, end);
行 224:
行 225:        if (str.Length > end)以下是代码
----------------------------------------------------------------------------------
public static string leftstr(string str, int len)  
    {
        int intlen = str.Length;
        int start = 0;
        int end = intlen;
        int single = 0;
        char[] chars = str.ToCharArray();
        for (int i = 0; i < chars.Length; i++)
        {
            if (Convert.ToInt32(chars[i]) > 255)
            {
                start += 2;
            }
            else
            {
                start += 1;
                single++;
            }
            if (start >= len)
            {
                if (end % 2 == 0)
                {
                    if (single % 2 == 0)
                    {
                        end = i + 1;
                    }
                    else
                    {
                        end = i;
                    }
                }
                else
                {
                    end = i + 1;
                }
                break;
            }
        }
        str = str.Replace("<br>", "\n");
        str = str.Replace("<br />", "\n");
        str = str.Replace("<br/>", "\n");
        string temp = str.Substring(0, end);        if (str.Length > end)
        {
            return temp + "…";
        }
        else
        {
            return temp;
        }
    }