?
Solved

String Length

Posted on 2003-04-01
5
Medium Priority
?
344 Views
Last Modified: 2011-09-20
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
Comment
Question by:greg222
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:Lasse_Lasse
ID: 8246260
Use the len command: eks
text = "ksdjf"
len(text) = 5
0
 

Accepted Solution

by:
BlackFire earned 80 total points
ID: 8246285
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
 
LVL 3

Expert Comment

by:emadat
ID: 8246317
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
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8246772
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
 
LVL 10

Expert Comment

by:aeklund
ID: 8247340
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question