Solved

Loop to fill in a string

Posted on 2008-10-02
6
285 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
ID: 22628704
do you mean how to encode the string to have the % codes?
0
 

Author Comment

by:chadmanvb
ID: 22629095
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
ID: 22629365
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:chadmanvb
ID: 22629406
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
ID: 22629456
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
ID: 31502564
Thanks so much, that worked great!  Chad
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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