I am initialising a StringBuilder as follows:
StringBuilder builder = new StringBuilder("Symptoms are ");
After this I loop through a list and add each string item to the end using
foreach(var item in list)
{
builder.Append(item);
}
An example item would be something like “headache” but once i’ve appended it to “Symptoms are ” and called builder.ToString() it shows:
"Symptoms areHeadache...etc"
as opposed to
"Symptoms are Headache...etc"
Why is it ignoring the space?
Since the code you’ve provided doesn’t produce the problem you’ve described, I’m guessing that your actual problem is a lack of whitespace between the symptoms (items). In that case, I’d suggest using
String.Join()like so:Now your items will be comma-separated with a padding space between.