Solved

Loop to fill in a string

Posted on 2008-10-02
6
281 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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