Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing the Last Character in a string 1

Status
Not open for further replies.

Minkers

Technical User
Dec 15, 2004
70
US
I have a string that gets data from a table to display in a text box. The string is Value1, value2, value2, and so on, always ending with a comma. How do I removed the comma on the last one? I don't want to take it out of the string creation code as it needs it there, I just want to have a line that removes the very last comma from the string.

Thanks in advance!
Minkers
 
Dim strName as String
Dim intSizeOfString as Integer
Dim strNewString as String

strName = "Value1, value2, value3,"

intSizeOfString = Len(strName)
strNewString = Left(strName, intSizeOfString - 1)
MsgBox strNewString
 
This did not work, I am getting the same string as before, with the comma still on the end. :(
 
How about...

YourStringName = Left(YourStringName, Len(YourStringName) - 1)

Randy
 
Didn't think about the space. how about...

YourStringName = Trim(YourStringName)
YourStringName = Left(YourStringName, Len(YourStringName) - 1)



Randy
 
Another way (ac2k or above):
NewString = Left(OldString, InStrRev(OldString, ",") - 1)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top