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!

Removing last character of string 2

Status
Not open for further replies.

lunargirrl

Programmer
Jan 26, 2004
77
BR
Hello people,
I would like to remove the last character of my string.

e.G. LisaManson2 (i would extract only the character '2' of the string). I am trying to do:

mystr = (mystr- Right(mystr, 1))

It doenst work at all.
How could I do that??

TIA,
venus
 
hi zarkon4, thanks for the quick answer
but it seems to dont work. :(
I wanted my result to be 'LisaManson' only, i want to throw away the number 2.

thanks,
venus
 
Sorry, forgot an important part.

mystr=mid$(mystr,1,len(mystr)-1))
 
Now try that with an empty string...

See what happens when it tries to do a mid from -1...

mmilan.

Ps. Solution - test for the special case of empty string before calling Zarkon4's code...
 
Here is code to check for empty string.

mystr = IIf(IsNull(mystr), "", _
Mid$(mystr, 1, Len(mystr) - 1))
 
That code will not check for an empty string. It will only check if that value of the string is NULL - which is NOT the same thing as empty.

some better code would be
Code:
mystr = IIF(mystr & vbNullString = "", Mid$(mystr, 1, Len(mystr)-1))
 
Sorry, left off a part

Code:
mystr = IIF(mystr & vbNullString = "", [b]"",[/b] Mid$(mystr, 1, Len(mystr)-1))
 
You could try this:

Dim mystr As String
mystr = "LisaManson2"
MsgBox Left(mystr, Abs((Len(mystr) - 1)))

mystr = ""
MsgBox Left(mystr, Abs((Len(mystr) - 1)))

Swi
 
thanks a lot people!
I really appreciate what you done to help me.



:****
venus
 
venus,
You might find this link very helpful:

Visual Basic Tutorial

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
I took a look at it and found a lot of nice stuff there.
Thank you for the tip JCruz063!

:*
venus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top