-2
   An array of Image Url path:
    ["http://cdncms.fonts.net/hero-images/FEX_Hero_Thumb.png ","http://cdncms.fonts.net/hero-images/Wilma_Hero_Thumb.png "]


   asp.net mvc  Controller :
     public ActionResult Extract(string[] name)
            {
                //List<string> myList = name.ToList<string>();


                  for(int x = 0; x < name.Length; x++)
                  {
                  //string something = name[x];
                  var item = name[x];



                  Session["values"] = item;
                  }
                  char[] delimiter1 = new char[] { ',' };   // <-- Split on these


                string[] array1 =  Session["values"].ToString().Split(delimiter1, StringSplitOptions.RemoveEmptyEntries);
                     foreach (var item in array1)
                        {


                            string exts = Path.GetExtension(item); //illegal character 
                            string strRealname = Path.GetFileName(item); illegal character
                         }

我知道这个问题是由于 [ 开头和最后一个字符的存在。我尝试过但没有成功。知道如何在 C# 中使用 split 函数删除它

4

1 回答 1

0

Assuming that you have correctly identified the problem, you could do this before making it an array:

var values = Session["values"].ToString();
if(values.StartsWith("[")) values = values.Substring(1);
if(values.EndsWith("]")) values = values.Substring(0, values.Length - 1);
于 2013-06-26T07:10:09.280 回答