Best way to remove the last character from a string built with stringbuilder

后端 未结 12 2381
-上瘾入骨i
-上瘾入骨i 2020-12-23 14:30

I have the following

data.AppendFormat(\"{0},\",dataToAppend);

The problem with this is that I am using it in a loop and there will be a t

12条回答
  •  一向
    一向 (楼主)
    2020-12-23 15:04

    I recommend, you change your loop algorithm:

    • Add the comma not AFTER the item, but BEFORE
    • Use a boolean variable, that starts with false, do suppress the first comma
    • Set this boolean variable to true after testing it

提交回复
热议问题