How to remove comma at last index of type string builder?

Hello, I have sample string builder by append different values " ," comma separated.
Eg. Items: Apple,Orange, I need to remove at last index “,” which is after orange. Can anyone suggest the solution?

Thanks

Hi @ManojKumarV ,

Maybe try the below :

YourStringVar.TrimEnd(",".ToCharArray)

string builder does not have TrimEnd method.

@ManojKumarV ,

Maybe Conversion to string and then reconvert back to StringBuilder :

new StringBuilder(YourStringBuilderVar.ToString.TrimEnd(",".ToCharArray))

image

Hi,

In this case, perhaps we should use string which is converted from StringBuilder.

Can you check the following MS official document - The String and StringBuilder types section.

Hope this helps you.

Regards,

but, this is has been removing all the " ," occurrences.

@ManojKumarV ,

Could you show us what have you tried ?

If you can maybe provide us a Screenshot of the usage/implementation like provided above, it would help us understand what was the issue.

Items = Open,Closed,
Items = new StringBuilder(Items.ToString.TrimEnd(“,”.ToCharArray))
this is what I have tried , but got Items= OpenClosed as output

@ManojKumarV ,

I think I was able to get the right output :
image