문제

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