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

Stripping extra spaces in middle of query string 1

Status
Not open for further replies.

davmorr

Programmer
Mar 30, 2002
3
US
How can I most efficiently reduce additional spaces between character strings to just one space.
Ex:
From
"string1 string2 string3"
To
"string1 string2 string3"

This is for a database search where the the form submission is converted to an array of strings and queried against the db. The spaces throw a monkey wrench into the mix.
 
<%
Dim i, list
list = &quot;string1 string2 string3&quot;
list = Split(list,&quot; &quot;)

For i = 0 to UBOUND(list)
list(i) = Trim(list(i))
Next

list = Join(list,&quot; &quot;)

Response.write(list)
%>

Should produce:
--------------------

string1 string2 string3


--------------------

Hope this helps. -Ovatvvon :-Q
 
Unless the amount of spaces is exactly the same all the time...like, if there will ALWAYS be 4 spaces between each word, then you can use the replace command...

<%
list = Replace(list, &quot; &quot;, &quot; &quot;)
%>

This replaces every part with 4 spaces into 1 space.

Otherwise, if you don't know how many spaces there will be...use the first messages method. -Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top