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

Remove Last Character from String Variable 2

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
0
0
US
How can you remove the last character from a string variabler?

For example, change MikeX to Mike as shown below.
Code:
[blue]Dim[/blue] strName [blue]as String[/blue]
strName = "MikeX"
[b]strName after removing last character = "Mike"[/b]

Thanks.

Regards,
Mike

"Don’t get suckered in by the comments – they can be terribly misleading. Debug
only code. – Dave Storer."
 
Code:
strName = left(strName,len(strName)-1)

not sure if len is the length property of the string.
 
Perfect - Thanks.

Regards,
Mike

"Don’t get suckered in by the comments – they can be terribly misleading. Debug
only code. – Dave Storer."
 
another way....

strName.Substring(0, (strName.Length - 1))

Scott
Programmer Analyst
<{{><
 
ThatRickGuy have got a star but his shorter solution will return only X.
stnkyminky has the correct and also .Net solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top