Hi,
I'm trying to pass a querystring with certain common words removed (and,
the, if, of etc). The code below replaces the keywords with "" or whatever I
choose, but what I'd like to do is remove the words completely from the
querystring. How do I remove rather than replace?
Thanks
*********
tempstr=searchstring
removewords = array ("and","the","if","of","a")
temp=trim(tempstr)
for x=0 to ubound(removewords)
temp=replace(temp,removewords(x),"")
next
newstring=Trim(temp) 11 1631
David wrote: Hi,
I'm trying to pass a querystring with certain common words removed (and, the, if, of etc). The code below replaces the keywords with "" or whatever I choose, but what I'd like to do is remove the words completely from the querystring. How do I remove rather than replace?
Thanks
********* tempstr=searchstring
removewords = array ("and","the","if","of","a") temp=trim(tempstr)
for x=0 to ubound(removewords) temp=replace(temp,removewords(x),"") next
newstring=Trim(temp)
I don't understand. Replacing characters with an empty string is exactly the
same thing as removing them. Could you reprase your question?
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows wrote on 15 feb 2004 in
microsoft.public.inetserver.asp.general: I don't understand. Replacing characters with an empty string is exactly the same thing as removing them. Could you reprase your question?
Bob, when removing words double spaces are left.
Also another problem:
removewords = array ("and","the","if","of","a") temp=trim(tempstr)
for x=0 to ubound(removewords) temp=replace(temp,removewords(x),"") next
"the cat has offended their wife"
will be changed to
" ct hs fended ir we"
I would suggest this:
==========================
removewords = array ("and","the","if","of","a")
temp= " " & trim(tempstr) & " "
for x=0 to ubound(removewords)-1
temp=replace(temp, " " & removewords(x) & " "," ")
next
result = trim(temp)
==========================
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
> I would suggest this:
<snip>
Thanks - works a treat!
David
"David" wrote:
: > I would suggest this:
: <snip>
:
: Thanks - works a treat!
Not if you want to remove all words case-insensitive. And, you're missing
the last array element.
lbound(array) is always 0
ubound(array) is always count - 1
So, these lines:
for x=0 to ubound(removewords)-1
temp=replace(temp, " " & removewords(x) & " "," ")
Should be:
for x=0 to ubound(removewords)
temp=replace(lcase(temp), " " & removewords(x) & " "," ")
Test:
<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
dim removewords, tempstr, x, result, temp
tempstr = "If a cat and a dog have a battle of wits, who will win the
battle?"
removewords = array ("and","the","if","of","a")
temp= " " & trim(tempstr) & " "
for x=0 to ubound(removewords)
temp=replace(lcase(temp), " " & removewords(x) & " "," ")
Response.Write(temp & ": removing " & removewords(x) & "<br />" &
vbCrLf)
next
result = trim(temp)
Response.Write("old: " & tempstr & "<br />" & vbCrLf)
Response.Write("new: " & result & "<br />" & vbCrLf)
%> http://kiddanger.com/lab/stripcommon.asp
HTH...
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Roland Hall wrote on 16 feb 2004 in
microsoft.public.inetserver.asp.general: And, you're missing the last array element.
lbound(array) is always 0 ubound(array) is always count - 1
Yes, my mistake
Not if you want to remove all words case-insensitive.
I would hesitate to remove the "A" or even the "a" for that matter.
The logical choice should be to remove all single letter words as search
words.
And for that regular expressions should take over,
or, if you are unconfortable with that, a split-join sequence.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
"Evertjan." wrote:
: Roland Hall wrote on 16 feb 2004 in
: microsoft.public.inetserver.asp.general:
:
: > And, you're missing the last array element.
: >
: > lbound(array) is always 0
: > ubound(array) is always count - 1
:
: Yes, my mistake
I'm not error free either.
: > Not if you want to remove all words case-insensitive.
:
: I would hesitate to remove the "A" or even the "a" for that matter.
:
: The logical choice should be to remove all single letter words as search
: words.
Agreed, unless enclosed within quotes.
: And for that regular expressions should take over,
: or, if you are unconfortable with that, a split-join sequence.
I prefer regular expressions. Not sure about others.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
"Roland Hall" wrote:
: "Evertjan." wrote:
: : And for that regular expressions should take over,
: : or, if you are unconfortable with that, a split-join sequence.
:
: I prefer regular expressions. Not sure about others.
RegExp version:
It still needs work. This doesn't appear to be the most efficient use.
<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
dim temp, tempstr, result, re, Match, Matches
tempstr = "If a cat and, and a dog have a battle of wits, who will win the
battle? I, and I do mean 'I', think the dog would win."
Response.Write("old: " & tempstr & "<br />" & vbCrLf & "<hr>")
temp = " " & trim(tempstr) & " "
set re = new RegExp
with re
.Global = True
.IgnoreCase = True
.Pattern = "(( and | and, )|( the | the, )|( if | if, | if\. | if\? )|( of
| of, | of\. | of\? )|( \w | \w, | \w\. | \w\? ))"
end with
set Matches = re.Execute(temp)
for each Match in Matches
temp = re.Replace(" " & temp & " "," ")
next
result = trim(temp)
Response.Write("RegExp: " & re.Pattern & "<br />" & vbCrLf & "<hr>")
Response.Write("new: " & result & "<br />" & vbCrLf)
%> http://kiddanger.com/lab/stripcommonre.asp
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Roland Hall wrote on 16 feb 2004 in
microsoft.public.inetserver.asp.general: It still needs work. This doesn't appear to be the most efficient use.
<script language=vbs>
' prepare IE vbs pseudo ASP test environment
set response = document
temp = "If a cat and, and a dog have a battle of wits, who will win
the battle? I, and I do mean 'I', think the dog would win."
Response.Write "old:<br>" & temp & "<br><hr>" & vbCrLf
temp = " " & temp & " "
set re = new RegExp
re.Global = True
re.IgnoreCase = True
' loose comma's, question marks, etc.
re.Pattern = ",|\?|!"
temp = re.replace(temp," ")
' loose beginning and ending single quotes, not O'Brian
re.Pattern = "' | '"
temp = re.replace(temp," ")
' loose single letter or number words
re.Pattern = "\s\S\s"
temp = re.replace(temp," ")
' loose these 4
re.Pattern = " and | the | if | of "
temp = re.replace(temp," ")
' loose multiple white space = inner trim
re.Pattern = "\s+"
temp = re.replace(temp," ")
' outer trim, regex for the fun of it
re.Pattern = "(^\s+)|(\s+$)"
temp = re.replace(temp,"")
Response.Write "new:<br>" & temp & "<br>" & vbCrLf
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
"Evertjan." wrote:
: Roland Hall wrote on 16 feb 2004 in
: microsoft.public.inetserver.asp.general:
:
: > It still needs work. This doesn't appear to be the most efficient use.
:
: <script language=vbs>
:
: ' prepare IE vbs pseudo ASP test environment
: set response = document
:
: temp = "If a cat and, and a dog have a battle of wits, who will win
: the battle? I, and I do mean 'I', think the dog would win."
:
:
: Response.Write "old:<br>" & temp & "<br><hr>" & vbCrLf
:
: temp = " " & temp & " "
:
: set re = new RegExp
: re.Global = True
: re.IgnoreCase = True
:
: ' loose comma's, question marks, etc.
: re.Pattern = ",|\?|!"
: temp = re.replace(temp," ")
:
: ' loose beginning and ending single quotes, not O'Brian
: re.Pattern = "' | '"
: temp = re.replace(temp," ")
:
: ' loose single letter or number words
: re.Pattern = "\s\S\s"
: temp = re.replace(temp," ")
:
: ' loose these 4
: re.Pattern = " and | the | if | of "
: temp = re.replace(temp," ")
:
: ' loose multiple white space = inner trim
: re.Pattern = "\s+"
: temp = re.replace(temp," ")
:
: ' outer trim, regex for the fun of it
: re.Pattern = "(^\s+)|(\s+$)"
: temp = re.replace(temp,"")
:
:
: Response.Write "new:<br>" & temp & "<br>" & vbCrLf
:
: </script>
Why would you want to lose beginning and ending single quotes? This is a
search routine to remove common words but if someone wanted to use a common
word as part of their query, as you can do with Google, you will need to be
able to use quotes. Also, there is nothing regarding double quotes. We're
using this static but I'm almost sure this is designed to work with user
input.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Roland Hall wrote on 16 feb 2004 in
microsoft.public.inetserver.asp.general: Why would you want to lose beginning and ending single quotes? This is a search routine to remove common words but if someone wanted to use a common word as part of their query, as you can do with Google, you will need to be able to use quotes. Also, there is nothing regarding double quotes. We're using this static but I'm almost sure this is designed to work with user input.
This is not about the exact implementation but about the systematic "how"
of regex. I suppose by showing you my code, that is the main purpose.
You can always adapt it to your needs.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
"Evertjan." wrote:
: Roland Hall wrote on 16 feb 2004 in
: microsoft.public.inetserver.asp.general:
:
: > Why would you want to lose beginning and ending single quotes? This
: > is a search routine to remove common words but if someone wanted to
: > use a common word as part of their query, as you can do with Google,
: > you will need to be able to use quotes. Also, there is nothing
: > regarding double quotes. We're using this static but I'm almost sure
: > this is designed to work with user input.
:
: This is not about the exact implementation but about the systematic "how"
: of regex. I suppose by showing you my code, that is the main purpose.
: You can always adapt it to your needs.
Ok, fair enough. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Patrick |
last post by:
Hello, after learning that I was taking a class in VB.NET, I have been
drafted to solve all my companies VB/scripting problems - hey, I should know
everything; I've already taken 6 classes ;) I...
|
by: Colin Steadman |
last post by:
My ASP page allows user to enter comments into a form. To avoid
errors I'm having to strip out double quotes before saving to the
database. Is there anyway to encode these so that I can store...
|
by: Thor W Hammer |
last post by:
Smart algorithm for normalizing strings anyone?
Example:
If the original string looks like this:
"the brown
fox "
I want it end up like this:
"the brown fox"
|
by: Alex |
last post by:
I have a question about determining if one QueryString keys exists. The idea is, if this key exists, than its presence is enough to indicate that its value is true. For example ...
...
|
by: Lu |
last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following
problem. In javascript, I'm passing in:
"somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
|
by: Spondishy |
last post by:
Hi,
I'm looking for help with a regular expression and c#.
I want to remove all tags from a piece of html except the following.
<a>
<b>
<h1>
<h2>
|
by: Edward Elliott |
last post by:
I'm looking for the "best" way to strip a large set of chars from a filename
string (my definition of best usually means succinct and readable). I
only want to allow alphanumeric chars, dashes,...
|
by: Lo'oris |
last post by:
I'd like to have a set of "allowed characters", and strip a string
from everything besides those.
I've tried and tried but so far every time I enter strings containing
unicode, it goes mad and...
|
by: pingsheng |
last post by:
Dear all,
I have a form with dynamically created input fields. These fields go to next page for submitting into SQL database. The thing is all fields are the same but 4 fields. So each record...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |