String Length

What command can i use to get the length of a string, not including the end character. I am reading a password string from a text file and want to exclude the end character. The string could be any lenght.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use the len command: eks
text = "ksdjf"
len(text) = 5

dim Password as string, length as integer

open "password-file.txt" for input as #1
input #1, Password
close #1

length = len(Password)

' len() is the command.  you may also use trim() to remove end spaces.  example:  len(trim(password))


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
To get the length of a string:
iLength = Len(sString)

To get the length of a string without the last character:
iLength = Len(sString)-1

To set the length of a string without the last character:
sString = Left(sString, Len(sString)-1)

in VB there is NO 'end character' are probably thinking of a C type string, which is terminated with a Null character (ASCII Code 0).  VB strings are NOT terminated that way.  

Returns the string up to the trailing null, or the passed string if none.

' Copyright ©1996-2003 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce
'               or publish this code on any web site,
'               online service, or distribute as source
'               on any media without express permission.
Private Function TrimNull(item As String) As String

   Dim pos As Integer

   pos = InStr(item, Chr$(0))

   If pos Then
         TrimNull = Left$(item, pos - 1)
   Else: TrimNull = item
   End If

End Function
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.