Abdur Rahim
Abdur Rahim

Reputation: 4021

Removing Last Comma

I have a string like:

SELECT Sparte_id, Registernummer, Gesellschaft_ID, pk_id, Gesellschaft_Name, gesellschaft_crm,

Now I want to remove the last ,(comma) from the string. There are one, two, or three spaces after the last comma.

I am thinking of removing the last few letters. How could I do this?

Upvotes: 1

Views: 2824

Answers (2)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174309

Use string.TrimEnd:

var result = query.TrimEnd(',', ' ', '\n');

Upvotes: 7

krajew4
krajew4

Reputation: 839

One suggestion - it looks like you're trying to build list of fields (comma separated) - try using:

var fields = new List<string>();
var csv = fields.Aggregate((x,y) => x + ";" + y);

Upvotes: 0

Related Questions