Solved

Loop to fill in a string

Posted on 2008-10-02
6
253 Views
Last Modified: 2013-11-07
I have a web address I need to create from words in a string.  The location string will change and might have more or less in it, but looks something like:

CN=SerialNumber, OU=Desktops, OU=Home Office, OU=US, OU=Devices

The web page address that I need created would look like:

http://TEST:3467/ldap/browse.tsp?dn=CN%SerialNumber%2c+OU%3dDesktops%2c+OU%3dHome+Office%2c+OU%3dUS%2c+OU%3dDevices%2c+DC%3dtestdomain%2c+DC%3dcom%2c

How can I use vb2005 net to create this web address based on the location string.  The location string will always start with a CN=, but might have a single or multiple OU=.

Hope that makes sense.  Chad
0
Comment
Question by:chadmanvb
  • 3
  • 2
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
do you mean how to encode the string to have the % codes?
0
 

Author Comment

by:chadmanvb
Comment Utility
Sorry, I mean I would like to take my location string:
CN=SerialNumber, OU=Desktops, OU=Home Office, OU=US, OU=Devices

And use that to create a new string that will be the web page.  So it would somehow take create:

String1 = SerialNumber.replace(" ","+")
String2= Desktops.replace(" ","+")
String3= Home Office.replace(" ","+")
String4= US.replace(" ","+")
String5=Devices.replace(" ","+")

Webstring="http://TEST:3467/ldap/browse.tsp?dn=CN%" & String "1%2c+OU%3d" & String2 & "2%2c+OU%3d" "String3 & "%2c+OU%3d" & String4 & "%2c+OU%3d" String5 & "%2c+DC%3dtestdomain%2c+DC%3dcom%2c"

I am just not sure how to create all of these strings from my location string.  I think I could do it if I knew it would always contain 5 variables, but it could contain more or less.  Chad
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 300 total points
Comment Utility
there is a ready-made function for this. Having your string yet concatenated, use:

Dim s as String = "CN=SerialNumber, OU=Desktops, OU=Home Office, OU=US, OU=Devices"

Dim encoded as String = HttpUtility.UrlEncode(s)

You will need
Imports System.Web


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:chadmanvb
Comment Utility
Could you explain how this works?  I am not able to get it working.  Chad
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
Comment Utility
I don't do web stuff so I though that was a pretty cool answer jaime...  =)

For WinForms, I had to add a Reference to System.Web:

        ' For WinForms: Click on Project --> Add Reference, Select "System.Web" and Click "OK".
        Dim Prefix As String = "http://TEST:3467/ldap/browse.tsp?dn="
        Dim locations As String = "CN=SerialNumber, OU=Desktops, OU=Home Office, OU=US, OU=Devices"
        Dim locations2 As String = ", DC=testdomain, DC=com"

        Dim WebString As String = Prefix & System.Web.HttpUtility.UrlEncode(locations & locations2)
        Debug.Print(WebString)

0
 

Author Closing Comment

by:chadmanvb
Comment Utility
Thanks so much, that worked great!  Chad
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now