Question

I had a query string end with :

where id in (.....,11,)

and I want to remove the last "," to work correct I try this :

string test = id_case[i];
id_case[i] = test.Substring(Math.Max(0,test.Length -2));
id_case[i] += test.Substring(Math.Max(test.Length-1,test.Length)) + ")";

but didn't work the whole " where .... " is disappear
any help ?

Was it helpful?

Solution

This will remove the last comma in your query string:

var q = "where id in (.....,11,)";
q = q.Remove(q.LastIndexOf(','),1);

OTHER TIPS

It would probably be cleaner to remove the comma at the source, but one method is to do:

string[] parts = test.Split(',');
test = string.Join(",",parts.Take(parts.Length - 1))
     + parts[parts.Length-1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top