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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to delet last character of String 2

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
Does anybody know how to delete the last character of a string.
example
dim value as string
value="NAME1"

I need to edit the string so I get
value="NAME"

Thanks
 
Try this:
[tt]
value = "NAME1"
value = Left(value, Len(value) - 1)
Msgbox value
[/tt]
hth,
GGleason
 
On the same idea how can i get:

Value = "W18x106"

to read

Value = "106"

Bill
 
What if you have a field like the following list

name1
name2
name3@
name4
name5%
name6%
etc...

Where @ and % represent unprintable characters you want to strip. How can you modify the following code to strip only unprintable characters?


value = "NAME1"
value = Left(value, Len(value) - 1)
Msgbox value

Sign,
Desperate :-(
 
tjessejeff,
are those the only characters that might show up in the value? or are those just examples? Will the non-printing characters always be on the right side or will they show up in the middle of the string sometimes?
 
To tjessejeff,

You will have to have a looping function to evaluate each character.

Something like:
[tt]

Public Function strNew(value As Variant) As String
Dim i As Long

strNew = ""
For i = 1 To Len(value)
If Asc(Mid(value, i, 1)) >= 48 And Asc(Mid(value, i, 1)) <= 57 Then
' Include numbers 0 to 9
strNew = strNew + Mid(value, i, 1)
ElseIf Asc(Mid(value, i, 1)) >= 65 And Asc(Mid(value, i, 1)) <= 90 Then
' Include characters A to Z
strNew = strNew + Mid(value, i, 1)
ElseIf Asc(Mid(value, i, 1)) >= 97 And Asc(Mid(value, i, 1)) <= 122 Then
' Include characters a to z
strNew = strNew + Mid(value, i, 1)
Else
' Omit this character
End If
Next i
End Function

[/tt]

Add your own error trapping.

hth,
GGleason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top