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

Split QueryString? 2

Status
Not open for further replies.

whatsthehampton

Programmer
Sep 13, 2005
121
CA
Hi all,

How can I take a query string such as:-

?Folder=Folder1/Folder2/Folder3

and split it into

?Folder=Folder1/Folder2

Just taking off the last part of the querystring?

Thanks in advance,

j


 
There are several methods including:

1) Use the Split method of a String
2) Use the Substring method of a String

Have a go at one of those and post back if you get any problems


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
hi,

this is one way of doing this:


Dim theFolder() As String = Request.QueryString("folder").Split("/")
theFolder(theFolder.Length - 1) = ""
Response.Write("folder=" & String.Join("/", theFolder))


But i need to know why you are doing this? you want to extract some values from a query string and pass them back as querystring to some other page???

Known is handfull, Unknown is worldfull
 
Thanks ca8msm and vbkris,

I am Googling substrings as we speak and I've almost got vbkris' going with

Dim qsx As String = SplitQueryString(Request.QueryString("folder"))
Protected Function SplitQueryString(ByVal qs As String) As String
Dim theFolder() As String = qs.Split("/")
theFolder(theFolder.Length - 1) = ""
Return (String.Join("/", theFolder))
End Function

But it is leaving the trailing '/' which is causing me problems?

What I am trying to do is navigate forwards and backwards through a members own online folder system.

Cheers,

Jon

 
try this:

If (Request.QueryString("folder").IndexOf("/") > 0) Then
Dim theFolder() As String = Request.QueryString("folder").Split("/")
theFolder(theFolder.Length - 1) = ""
Dim theResultString As String = String.Join("/", theFolder)
Response.Write(theResultString.Substring(0, theResultString.Length - 1))
End If

you will need to use substrings...

Known is handfull, Unknown is worldfull
 
An easier method would be just using the second item I suggested e.g.
Code:
        Dim s As String = Request.QueryString("folder")
        Dim t As String = s.Substring(0, s.LastIndexOf("/"))


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks ca8msm!

A star for you too.

That works but sometimes I get

"
Length cannot be less than zero.
Parameter name: length
"

Because; I am using Forms Auth to define the root folder so no else can get to it.
Therefore my first URL is just which maps to the logged in users' folder (Which is His/Her unique username)

From there I need to go back and forward.

With vbkris' code I have to check the Parent directory of the last QueryString request against the users Root folder.

Hmm..
Am I doing this all wrong?

Cheers,
j

 
when doing SubStrings...and most other string methods to manipulate your values you should always validate you are going to return a value prior to performing them and or what you are attempting to perform on them is valid.

examples shown were examples but you still need to use some programming methods to keep your code safe :)


____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
The example I gave will simply return a string up until the last occurance of a forward slash. Is that not what you want to do?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top