下面代码在 int li_str = Convert.ToInt16(ls_str);
会报 “输入字符串的格式不正确。”的错误string[] index_temp;
string indexStr="24503;22269;19993;32452;32852;36187;";
index_temp = indexStr.Split(';');
indexStr = "";
for (int j = 0; j < index_temp.Length; j++)
{
    if (index_temp[j] != "")
    {
        string ls_str = index_temp[j];
        int li_str = Convert.ToInt16(ls_str);
        char lc_str = (char)li_str;        indexStr = indexStr + lc_str.ToString();
    }
}

解决方案 »

  1.   

    string[] indexStr = Regex.Split(indexStr, ";", RegexOptions.IgnoreCase);
      

  2.   

    string[] index_temp = Regex.Split(indexStr, ";", RegexOptions.IgnoreCase);
      

  3.   


                string[] index_temp;
                string indexStr = "24503;22269;19993;32452;32852;36187;";
                index_temp = indexStr.Split(';');
                indexStr = "";
                for (int j = 0; j < index_temp.Length; j++)
                {
                    if (index_temp[j] != "")
                    {
                        string ls_str = index_temp[j];
                        int li_str = int.Parse(ls_str);
                        char lc_str = (char)li_str;                    indexStr = indexStr + lc_str.ToString();
                    }
                }
                Console.Write(indexStr);
                Console.ReadLine();
      

  4.   


      string[] index_temp;
                string indexStr = "24503;22269;19993;32452;32852;36187;";
                index_temp = indexStr.Split(';');
                indexStr = "";
                for (int j = 0; j < index_temp.Length; j++)
                {
                    if (index_temp[j] != "")
                    {
                        string ls_str = index_temp[j];
                        Int32 li_str = Convert.ToInt32(ls_str);
                        char lc_str = (char)li_str;                    indexStr = indexStr + lc_str.ToString();
                    }
                }数值超过int16的值 用int32
      

  5.   

    int li_str = Convert.ToInt16(ls_str);
    应改为:
    Int32   li_str = Convert.ToInt32(ls_str);
      

  6.   

    改成这个
    int li_str = Convert.ToInt32(ls_str);
    你那个Convert.ToInt16长度太短了溢出了!
      

  7.   

    string indexStr="24503;22269;19993;32452;32852;36187;";
    按‘;’分割,数组的最后一个为空,所以转化为int时报错。
      

  8.   


     List<char> c = new List<char>();
                foreach (string str in indexStr.Split(';'))
                {
                    if (!string.IsNullOrEmpty(str))
                        c.Add(Convert.ToChar(Convert.ToInt32(str)));
                }
                indexStr = new string(c.ToArray());
      

  9.   

    hehe ...谢谢了分不多,每人分点
      

  10.   

    [Quote=引用 17 楼 kingdomgps 的回复:]
    引用 11 楼 xin_shui 的回复:
    string indexStr="24503;22269;19993;32452;32852;36187;"; 
    按‘;’分割,数组的最后一个为空,所以转化为int时报错。 
     
    这个是正解 这个就是你代码报错的根本原因这个是正解