I need assistance with formatting a string within my webform. Currently, I have a function that uses a for loop to output each item in my cart. However, I am struggling to include tab spaces and newline characters for better readability. Here is the code snippet:
public string Display()
{
CartClass CartList = CartClass.GetCart();
System.Text.StringBuilder sb = new StringBuilder();
for (int i = 0; i < CartList.CartList.Count(); i++)
{
Movies Movie = CartList.CartList[i];
sb.Append(String.Format(i + 1 + "." + "\t"
+ Movie.MovieName + "\t" + "£" + Movie.MovieCost.ToString() + "\n" ));
}
return sb.ToString();
}
It's worth noting that I display this string in an asp:listbox using the following function:
private void DisplayCart()
{
lstCart.Items.Clear();
lstCart.Items.Add(cart.Display());
}
However, the current output lacks proper formatting. I would like the final result to resemble a list format, like this:
- Up £5
- Madagascar £5
- Finding Nemo £5
How can I achieve this desired format?