473,395 Members | 1,468 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,395 software developers and data experts.

Removing the trailing comma from a string

hi there

i have this string
Expand|Select|Wrap|Line Numbers
  1. dim str as string
  2.  
  3. str="1,2,3,4,"
i required this
Expand|Select|Wrap|Line Numbers
  1. str="1,2,3,4"
can anyone help..!
Oct 6 '07 #1
8 11008
pbmods
5,821 Expert 4TB
Heya, Kashan. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=vb]
Visual Basic source code goes here.
[/CODE]

I'm going to go ahead and move this thread to the VB forum, where our resident Experts will be better able to help you out.
Oct 6 '07 #2
Killer42
8,435 Expert 8TB
i required this
Expand|Select|Wrap|Line Numbers
  1. str="1,2,3,4"
In what version of VB?
Oct 7 '07 #3
jamesd0142
469 256MB
In what version of VB?
There is a substring method in VB.Net, or a mid function in VB.

Either one of these will allow you to pick out characters at set positions and allow you to delete them.

You could for example in VB.
Expand|Select|Wrap|Line Numbers
  1. Dim str As String  = "1,2,3,4,"
  2. Dim str1 As String
  3.  
  4. Dim i As Integer = Len(str)
  5. str1 = Mid(str, 1, i - 1)
  6.  
This would pick out all characters except the last one which will be your comma, and store in str1.

Thanks JAmes
Oct 8 '07 #4
Killer42
8,435 Expert 8TB
Thanks for that, James.

However, if you're going to post code, please try to ensure it's working code.

Dim str As String = "1,2,3,4,"
...is VB.Net syntax and won't work in VB6 or earlier. In those versions you would need to do something like...

Expand|Select|Wrap|Line Numbers
  1. Dim str As String
  2. str = "1,2,3,4,"
Oct 8 '07 #5
jamesd0142
469 256MB
ahh i see, well thats a new 1 to me :P

I only use vb.net and didnt realise the small differences.
Oct 9 '07 #6
Killer42
8,435 Expert 8TB
ahh i see, well thats a new 1 to me :P

I only use vb.net and didnt realise the small differences.
:)
That's probably just about the smallest of the differences. Some are huge.

I downloaded VB 2005 Express Edition weeks ago. But I haven't done anything with it yet because I just don't know where to start. There's so much to learn.
Oct 9 '07 #7
jamesd0142
469 256MB
yes, maybe i should add that at home i use vb.net, and in work i downloaded the free vb 2005 express edition also, so im having to switch between the two! annoying!

although when i finally tried to use this i find little differences.

for example:

dim a as string = "123" works for both.

I understand this does'nt work for all versions of vb as you previously told me.

some versions require this???

dim a as string
a = "123"
Oct 10 '07 #8
I know this post may be pretty old but I found myself working in old VB6 code once more and had to create a couple of functions that removes characters from the start and end of a string so I wrote these functions. Maybe someone will find these useful if they're working with VB6 again.

Expand|Select|Wrap|Line Numbers
  1. Public Function TrimEnd(ByVal someString As String, ByVal someChar As String) As String
  2.  
  3.     On Error GoTo Err_Proc
  4.     someString = Trim(someString)
  5.     someChar = Trim(someChar)
  6.  
  7.     If Len(someString) = 0 Then GoTo Exit_Proc
  8.     If Right(someString, Len(someChar)) <> someChar Then GoTo Exit_Proc
  9.  
  10.     While Right(someString, Len(someChar)) = someChar
  11.         someString = Left(someString, Len(someString) - Len(someChar))
  12.     Wend
  13.  
  14. Exit_Proc:
  15.     TrimEnd = someString
  16.     Exit Function
  17.  
  18. Err_Proc:
  19.  
  20.     'Err_Handler True, Err.Number, Err.Description, Erl, "Form1", "Function TrimEnd"
  21.     MsgBox Err.Description
  22.     Err.Clear
  23.     Resume Exit_Proc
  24.  
  25. End Function
  26.  
  27. Public Function TrimStart(ByVal someString As String, ByVal someChar As String) As String
  28.  
  29.     On Error GoTo Err_Proc
  30.     someString = Trim(someString)
  31.     someChar = Trim(someChar)
  32.  
  33.     If Len(someString) = 0 Then GoTo Exit_Proc
  34.     If Left(someString, Len(someChar)) <> someChar Then GoTo Exit_Proc
  35.  
  36.     While Left(someString, Len(someChar)) = someChar
  37.         someString = Mid(someString, Len(someChar) + 1)
  38.     Wend
  39.  
  40. Exit_Proc:
  41.     TrimStart = someString
  42.     Exit Function
  43.  
  44. Err_Proc:
  45.  
  46.     'Err_Handler True, Err.Number, Err.Description, Erl, "Form1", "Function TrimStart"
  47.     MsgBox Err.Description
  48.     Err.Clear
  49.     Resume Exit_Proc
  50. End Function
  51.  
  52.  
May 5 '22 #9

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

Similar topics

2
by: David Lawson | last post by:
I need to trim off trailing 0x00's from a binary string. Does anyone know how? David
27
by: Alberto Vera | last post by:
Hello: I have the next structure: How Can I make it using Python? How Can I update the value of 6?
1
by: Andy Visniewski | last post by:
I have three columns, RecordID, FirstName, and LastName, but somehow through some program glitch, there is sometimes a trailing space in the firstname and lastname columns, for example, a persons...
6
by: jalkadir | last post by:
I am trying to find a way to remove the leading and tailing blanks from a string. What I have come up with is not doing the work as I expected; because if the value I pass to the function is "...
5
by: Tammy | last post by:
I am doing some genealogy research and I have discovered that there is a lot of data available on the web in text format. The problem is that the columns in the files are lined up by spaces. I'd...
14
by: bonehead | last post by:
Greetings, I'm using the DoCmd.TransferText method to export the results of a MS Access query to a csv file. The csv will then be used to load an Oracle table. In other systems such as TOAD...
3
by: Smythe32 | last post by:
Hi All, I am trying to remove carriage returns from a text field via some code. Here is an example of what I am up against. The field streetname contains the little square box that I believe...
3
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hello, I've eliminated the bulk of code, this should be sufficient: byte fromEncrypt; string sDecryptedString; //Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0,...
6
by: Jan Sneeuwman | last post by:
Hello, I am working on a library in C++, and the library goes with a header file with a trailing comma at the end of some enumeration. Like this: enum Abc { ENUM_ONE, ENUM_TWO ENUM_THREE,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.