Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

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.

thanks
0
greg222
Asked:
greg222
1 Solution
 
Lasse_LasseCommented:
Use the len command: eks
text = "ksdjf"
len(text) = 5
0
 
BlackFireCommented:
use:

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))


0
 
emadatCommented:
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)

0
 
Arthur_WoodCommented:
in VB there is NO 'end character'....you 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.  

AW
0
 
aeklundCommented:
TrimNull            
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now