How to create this string? Thank You.

  • Thread starter Thread starter Miguel Dias Moura
  • Start date Start date
M

Miguel Dias Moura

Hello,

I am calling an ASP.NET / VB as follows:
search.aspx?search=asp%20book%20london

Then I create a string with the keywords like this:
Dim keywords() As String =
Request.QueryString("search").Split(CChar(""))

It's not working. What am I doing wrong?

I also need to create a new string. Something as follows:
newString = "CONTAINS (*, 'keyword(1)') AND CONTAINS (*, 'keyword(2)')
AND ... CONTAINS (*, 'keyword(i)')"

I will need some kind of loop.

Can someone tell me what am I doing wrong on first code line and how to
create newString?

Thanks,
Miguel
 
It looks like you are missing your space character in your split statement.

Dim keywords as string()
keywords = s.Split( CChar( " " ) )

Here is a loop that will get you the result you are looking for.

Dim query as String = String.Empty
Dim i As Int32
For i = 0 To keywords.Length
query += String.Format("CONTAINS ( *, '{0}') ", keywords(i))
If i + 1 = keywords.Length Then
i = keywords.Length
Exit For
End If
query += " AND "
Next

HTH,

bill
 
Hi,

I tested your code but when I display the result I don't get anything.

Here is the code I am using:

Sub Page_Load(sender As Object, e As System.EventArgs)
If Request.QueryString("search") Is Nothing Then
Else
Dim keywords as string()
keywords = Request.QueryString("search").Split(CChar(" "))
Dim query as String = String.Empty
Dim i As Int32
For i = 0 To keywords.Length
query += String.Format("CONTAINS ( *, '{0}') ", keywords(i))
If i + 1 = keywords.Length Then
i = keywords.Length
Exit For
End If
query += " AND "
Next
Response.Write(query)
End If
End Sub

I called the page like this:
page.aspx?search?asp%20book%20london

Am I doing something wrong here?

Thanks,
Miguel
 
Hi,

My mistake. I was using a ? instead of a = in the URL.

Thank You Very Much for your help,
Miguel
 
Back
Top