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

easy string question 1

Status
Not open for further replies.

stucker79

Technical User
Dec 7, 2004
25
US
If I have a string value equal to "Firstname Lastname" and I want to separate the two into their own separate variables, how can i do that? i think i will need to use an instr to find the " " but I'm not sure what to do after that. I'm using the faq on access the active directory to get the full name of the user. I have this in a function call that is returning the full name:

Public Function GetUserInfo(ByVal domain As String, ByVal username As String, ByVal pwd As String) As String
Dim domainAndUsername As String = domain & "\" & username
Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd)
Dim strRealName As String

Dim Searcher As DirectorySearcher = New DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
Try
Searcher.Filter = ("(anr=" & username & ")")
result = Searcher.FindOne()
strRealName = result.Properties("givenName")(0).ToString() & " " & result.Properties("sn")(0).ToString()

Catch ex As Exception
Debug.Write(ex.Message)
End Try

Return strRealName

End Function

can i get the function to return two separate values? or will i have to get it to return the full name and then separate it later?
 
This code will split the "FirstName LastName" string into an array. element 0 will be "FirstName" element 1 will be "LastName"

Code:
dim Name() as string = strRealName.split(" ")

-Rick

----------------------
 
hey I never knew about the split method, that's great!! thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top