How to delete last character in a string in C#?

前端 未结 10 1992
一个人的身影
一个人的身影 2020-12-23 00:21

Building a string for post request in the following way,

  var itemsToAdd = sl.SelProds.ToList();
  if (sl.SelProds.Count() != 0)
  {
      foreach (var item         


        
10条回答
  •  不知归路
    2020-12-23 00:55

    build it with string.Join instead:

    var parameters = sl.SelProds.Select(x=>"productID="+x.prodID).ToArray();
    paramstr = string.Join("&", parameters);
    

    string.Join takes a seperator ("&") and and array of strings (parameters), and inserts the seperator between each element of the array.

提交回复
热议问题