Data cell ends with a comma

Marco
Contributor

Hi Everyone.
I have a DataCell that ends with a comma, and I wanted to know how I can remove it.

Example

Etc.
UD6Id: -999,
UD7Id: -999,
UD8Id: -999,

My issue is similar to the example, where after the UD8Id there is a comma with nothing following.

 

1 ACCEPTED SOLUTION

RobbSalzmann
Valued Contributor

Hi Marco,

It would help if you post the code that is producing this.  I'm going to assume you need to remove the last comma that is added using a loop that puts a comma at the end of a string on each iteration.  To resolve the extra comma that results, you can add(use whatever variable name you are using now for "strDataCellMembers"):
strDataCellMembers = strDataCellMembers.TrimEnd(",", c)

Often a  better approach is to create a List(Of String) and add the datacell member scripts to the list in your loop.  Then add the commas like this: 
Dim strDataCell As String = String.Join(",", lstDataCellElements)

This approach eliminates the need to manage the last extra comma that looping and appending a string or stringbuilder has.

View solution in original post

1 REPLY 1

RobbSalzmann
Valued Contributor

Hi Marco,

It would help if you post the code that is producing this.  I'm going to assume you need to remove the last comma that is added using a loop that puts a comma at the end of a string on each iteration.  To resolve the extra comma that results, you can add(use whatever variable name you are using now for "strDataCellMembers"):
strDataCellMembers = strDataCellMembers.TrimEnd(",", c)

Often a  better approach is to create a List(Of String) and add the datacell member scripts to the list in your loop.  Then add the commas like this: 
Dim strDataCell As String = String.Join(",", lstDataCellElements)

This approach eliminates the need to manage the last extra comma that looping and appending a string or stringbuilder has.