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

Trying to strip ADSI details

Status
Not open for further replies.

tazzer

Technical User
May 3, 2001
11
0
0
GB

Hi,

I am attempting to return specified characters from a string variable. The variable is called in session form from Active Directory - session("linemanager") - and the output is as follows:

CN=firstname.lastname,OU=Galwally and Local Offices,OU=Users,OU=InvestNI Users and Computers,DC=investni,DC=internal

I want to pull out the firstname.lastname part only out of the text string and have attempted to do so with code similar to below;

Function FnCleanString(pString)
Dim tString
Dim tLength
Dim lCtr
tString = session("linemanager")
tLength = Len(pString)
For lCtr = 1 To tLength
If Mid(pString, lCtr, 1) <> &quot; &quot; Then
tString = tString & Mid(pString, lCtr, 1)
End If
Next lCtr
FnCleanString = tString
End Function

I'm making a plead for help because I'm getting error messages all over no matter what code I attempt.

Any assistance you could provide would be mucho appreciated.

Tazzer
 
Does this help?

function getNames()
tString = session(&quot;linemanager&quot;)
commaPos = inStr(tString,&quot;,&quot;)
NameString = mid(tString,4,commaPos - 4)
periodPos =inStr(nameString,&quot;.&quot;)
firstName = left(nameString,(len(nameString)-periodPos))
lastName = mid(nameString,periodPos+1)

end function -- Just trying to help... LOL [ponder]
 
Hi tazzer,
This one may be a little more flexible. However, I think your input should be delimited by ; instead of , ... please double check.

<%
'-----------------------------------------------------------
' Note: You can do it easier with a Dictionary object,
' but I am doing this way because it is faster for simpler
' routine (Dictionary object is resource intensive.
'
' Note2: Will only extract the first instance of the Key
'-----------------------------------------------------------
function valueExtractor( vsInput, vsFieldName )
dim vaaDict, vsKeyValue, vasKeyValue

valueExtractor = &quot;&quot;
vaaDict = split( vsInput, &quot;,&quot; )
for each vsKeyValue in vaaDict
vasKeyValue = split( vsKeyValue, &quot;=&quot; )
vasKeyValue(0) = trim( vasKeyValue(0) )
vasKeyValue(1) = trim( vasKeyValue(1) )
if lcase( vasKeyValue(0) ) = lcase( vsFieldName ) then
valueExtractor = vasKeyValue(1)
exit for
end if
next

end function

dim vsToExtract, vsInput
vsInput = &quot;CN=firstname.lastname,OU=Galwally and Local Offices,OU=Users,OU=InvestNI Users and Computers,DC=investni,DC=internal&quot;

vsToExtract = &quot;CN&quot;
Response.Write( vsToExtract & &quot;=[&quot; & valueExtractor( vsInput, vsToExtract ) & &quot;]&quot; )
%>
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Shopping --> , Soccer --> ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top