I am building a string with StringBuilder.
StringBuilder Q = new StringBuilder(); Q.Append("INSERT INTO "); Q.Append(_lstview_item); Q.Append(" VALUES"); Q.Append("("); for (i = 0; i < col_no; i++) { Q.Append("'"); Q.Append(col_value[i]); Q.Append("'"); Q.Append(","); } Q.Append(")"); string query = Q.ToString();
However, I get a "," at the end of my line. I tried to use
string query = ext.Substring(0, ext.LastIndexOf(",") + 1);
to remove the excess "," , but it also removes the ")" .
How to remove only the last comma?
actual result : INSERT INTO .... VALUES('1','2','3',)
Desired result : INSERT INTO .... VALUES('1','2','3')
source share