Вопрос

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 ?

Это было полезно?

Решение

This will remove the last comma in your query string:

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

Другие советы

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top