Thanks lot!Its working,but I have again one doubt.I have created string but it looks like ('3435','4546', '546',).So plz tell me how to remove that last one comma,so that I can pass it thru sql query to show in grid.Thanking you!
how to remove last comma
Collapse
X
-
Tags: None
-
Why don't you post the code that you used to construct this string in the first place. That's what needs to be corrected.Originally posted by SuvarnaChaudhar iThanks lot!Its working,but I have again one doubt.I have created string but it looks like ('3435','4546', '546',).So plz tell me how to remove that last one comma,so that I can pass it thru sql query to show in grid.Thanking you!Comment
-
Since when did you start typing faster than me?Originally posted by Plateryou probably should generate that string in such a way that the comma is not there.
BUT, if there will ALWAYS be an extra comma at the end, you can use .LastIndexOf() to find the last index of the comma, then use that index in .Remove()
P.S Happy new year.Comment
-
I use this all the time to build sql criterias. If you are doing what I think you are, there are 2 ways that I use to handle the building of the comma delimited string for a SQL clause.
1) Basically, just always add a comma when adding an item to the comma delimited list. Then at the end, check to see if the last character is a comma and then remove it using
myString = myString.SubStr ing(0,myString. Length-1);
2) Before adding an item to the list, check to see if there are any items already in the list. If there are, then add a comma followed by the item you want to add to the list.
Hope this helps.Comment
Comment