- Home /
Remove the & at the end of concatenated string
I have 5 items
Apple
Banana
Melon
Grapes
Oranges
I have code that concatenates them into a string like so:
public void HasChanged ()
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append (" You have chosen: ");
foreach (Transform slotTransform in slots){
GameObject item = slotTransform.GetComponent<Slots>().item;
if (item){
builder.Append (item.name);
builder.Append (" & ");
}
}
inventoryText.text = builder.ToString ();
}
Which shows this:
You have chosen: Apples & Bananas & Melons & Grapes & Oranges &
My question is, how do I make it limited to only 5 items in order to remove the '&' at the end? Many thanks in advance!
Comment