How to cut a string ?

  • Thread starter Thread starter Ronny
  • Start date Start date
R

Ronny

Hi, I have this piece of code:

-----------
Dim user As String

user = Left(ap_GetUserName, 10)
Trim (user)

MsgBox Right(user, 5)
-----------

If the user is rwilliam, the msgbox shows iam. There are
som characters at the end of ap_GetUserName I want to get
rid off, because it is not possible to store user in a
table. If I set the number to 8 instead of 10 it works
great..

How do I check for valid characters?
 
try this function:

Public Function TrimNull(strVal As String) As String
' Trim the end of a string, stopping at the first
' null character.
Dim intPos As Integer
intPos = InStr(strVal, vbNullChar)
If intPos > 0 Then
TrimNull = Left$(strVal, intPos - 1)
Else
TrimNull = strVal
End If
End Function
 
Sorry, did not work, but I found anither solution. There
was an "error" in a function.. I replaced :

ap_GetUserName = strUserName

with

ap_GetUserName = Left(strUserName, InStr(1, strUserName,
Chr(0)) - 1)

Ronny
 
Back
Top