clean up code that simply removes the last comma of a comma separated string ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
The following works but I know it can be cleaned up. TempBeforeSending sends to another function a comma separated string with the last comma removed. <a rel="nofollow Thank you.
<div style="color:Black;background-color:White; <pre>
StringBuilder sbProductInfoUIDs = <span style="color:Blue; new System.Text.StringBuilder(<span style="color:#A31515; "");

<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < MyProductInfoItems.Count; i++)
{
<span style="color:Blue; if (MyProductInfoItems.IsChecked)
{
sbProductInfoUIDs.Append(MyProductInfoItems.ProductInfoUID.ToString() + <span style="color:#A31515; ",");
}
}
<span style="color:Blue; string Temp = sbProductInfoUIDs.ToString();
<span style="color:Blue; string TempBeforeSending = <span style="color:#A31515; "";
<span style="color:Blue; if (MyProductInfoItems.Count > 0)
{
TempBeforeSending = Temp.Remove(Temp.Length - 1, 1);
}
UpdateRequestProductInfo(MyProductInfoItems, TempBeforeSending);
[/code]


View the full article
 
Back
Top