473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

how to remove last comma

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!
Jan 11 '08 #1
5 1865
Plater
7,872 Expert 4TB
you 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()
Jan 11 '08 #2
r035198x
13,262 8TB
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!
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.
Jan 11 '08 #3
r035198x
13,262 8TB
you 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()
Since when did you start typing faster than me?
P.S Happy new year.
Jan 11 '08 #4
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.SubString(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.
Jan 11 '08 #5
bennett
12
Or you could just use the trimend

Expand|Select|Wrap|Line Numbers
  1. Dim strVariable As String  = "1,2,3,4,5,6,"
  2. strVariable = strVariable.TrimEnd(",")
  3.  
Liam
Jan 12 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: ted | last post by:
I'm having trouble using the re module to remove empty lines in a file. Here's what I thought would work, but it doesn't: import re f = open("old_site/index.html") for line in f: line =...
4
by: Stitch Jones | last post by:
I'm trying to get part of my perl script using a regex to get rid of an entire field between two ,'s I'm doing this to get a .csv formated alot nicer. here is an example of my issue user...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
3
by: blackdevil1979 | last post by:
Hi, I use a combobox to get a list of fruits (_SelectedIndexChanged)... I manage to get Apple, Orange, Grape, The question: How to get rid of the last comma (Grape , <--)
6
by: Rimuen | last post by:
Have a string contains numbers from database. But there is similar numbers want to remove Example: 1,3,6,6,6,12,13,14,15,15,15,15 Want to remove the similar numbers so it would be like:...
13
by: SuvarnaChaudhari | last post by:
Hi,I am new to .net. As per ur guidance I tried myString = myString.SubString(0,myString.Length-1); I also used str.lastindexof n str.remove,but by using this I m gettin string as ' (B193 '' H13 ''...
2
by: Dennis | last post by:
Here is what I am trying to do... I have an XML doc that looks like: <root> <node>value1</node> <node>value2</node> <node>value3</node> <node>value4</node> </root>
3
by: maheswaran | last post by:
Hi I have this (for sampple) abc,cde,efg,ghc, How can i remove this last , I knew there is a option using reqular expreesion but could not find the answer....
4
anfetienne
by: anfetienne | last post by:
hi im back again.......i have a code to create strings and save it within a text file to pass variables to flash. im using the string format below. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.