|
 |
asp_databases thread: Replace Method Question
Message #1 by "Pat Wong" <vinyl-junkie@n...> on Fri, 29 Nov 2002 09:09:14 -0800
|
|
I have a form where the user is allowed to enter a song title and begin browsing my database at
that point. In testing this, I discovered that a song title with an apostrophe in it will cause
an error, so I'm trying to figure out how to replace that with something that won't do that. I
came up with some convoluted code (not the Replace method, but something else) that replaces
the apostrophe with "'" (sans quotes). I don't know if that's exactly how I should be doing
it. If not, how?
I've been following the thread where someone suggested using the Replace method. I'm trying to
figure out how to do that but having a rough go of it. I came up with something that
unfortunately replaces the whole string with two apostrophes. Here's the relevant code. Can you
tell me what I'm doing wrong?
varBrowseSong = "Don't Go Breakin' My Heart"
Set regEx = New RegExp
regEx.IgnoreCase = True
varBrowseSong = regEx.Replace("'","'")
Response.Write varBrowseSong
Response.End
~8^) Pat Wong (ICQ #61070813)
http://www.napathon.com/
-------------------------------------------------------------------
"In the interests of cutting costs, the light at
the end of the tunnel has been switched off..."
-------------------------------------------------------------------
Message #2 by "Ian: Future Proof Web Dev" <lists@f...> on Fri, 29 Nov 2002 17:11:55 -0000
|
|
try:
varBrowseSong = "Don't Go Breakin' My Heart"
varBrowseSong = Replace(varBrowseSong,"'","'")
hth
ian
----- Original Message -----
From: "Pat Wong" <vinyl-junkie@n...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, November 29, 2002 5:09 PM
Subject: [asp_databases] Replace Method Question
> I have a form where the user is allowed to enter a song title and begin
browsing my database at
> that point. In testing this, I discovered that a song title with an
apostrophe in it will cause
> an error, so I'm trying to figure out how to replace that with something
that won't do that. I
> came up with some convoluted code (not the Replace method, but something
else) that replaces
> the apostrophe with "'" (sans quotes). I don't know if that's exactly
how I should be doing
> it. If not, how?
>
> I've been following the thread where someone suggested using the Replace
method. I'm trying to
> figure out how to do that but having a rough go of it. I came up with
something that
> unfortunately replaces the whole string with two apostrophes. Here's the
relevant code. Can you
> tell me what I'm doing wrong?
>
> varBrowseSong = "Don't Go Breakin' My Heart"
> Set regEx = New RegExp
> regEx.IgnoreCase = True
> varBrowseSong = regEx.Replace("'","'")
> Response.Write varBrowseSong
> Response.End
>
>
> ~8^) Pat Wong (ICQ #61070813)
> http://www.napathon.com/
> -------------------------------------------------------------------
> "In the interests of cutting costs, the light at
> the end of the tunnel has been switched off..."
> -------------------------------------------------------------------
>
>
>
Message #3 by "Pat Wong" <vinyl-junkie@n...> on Fri, 29 Nov 2002 09:46:24 -0800
|
|
Thanks! That worked like a charm. All of the examples that I looked at only had two arguments
in the Replace method (maybe I was looking at the wrong thing?).
Next question: Given that the string is now replaced with something that won't cause an error,
my browse is starting at the wrong place in the database. Any ideas why or what I can do to get
around it? I really need to solve this, as I'll be adding an exact match search to the page,
too. TIA
Here's the page in case that helps:
http://www.napathon.com/MusicDBSearch.asp?BrowseSong=Don%27t+Go+Breakin%27+My+Heart&page
----- Original Message -----
From: "Ian: Future Proof Web Dev" <lists@f...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, November 29, 2002 9:11 AM
Subject: [asp_databases] Re: Replace Method Question
| try:
|
| varBrowseSong = "Don't Go Breakin' My Heart"
| varBrowseSong = Replace(varBrowseSong,"'","'")
|
| hth
| ian
|
| ----- Original Message -----
| From: "Pat Wong" <vinyl-junkie@n...>
| To: "ASP Databases" <asp_databases@p...>
| Sent: Friday, November 29, 2002 5:09 PM
| Subject: [asp_databases] Replace Method Question
|
|
| > I have a form where the user is allowed to enter a song title and begin
| browsing my database at
| > that point. In testing this, I discovered that a song title with an
| apostrophe in it will cause
| > an error, so I'm trying to figure out how to replace that with something
| that won't do that. I
| > came up with some convoluted code (not the Replace method, but something
| else) that replaces
| > the apostrophe with "'" (sans quotes). I don't know if that's exactly
| how I should be doing
| > it. If not, how?
| >
| > I've been following the thread where someone suggested using the Replace
| method. I'm trying to
| > figure out how to do that but having a rough go of it. I came up with
| something that
| > unfortunately replaces the whole string with two apostrophes. Here's the
| relevant code. Can you
| > tell me what I'm doing wrong?
| >
| > varBrowseSong = "Don't Go Breakin' My Heart"
| > Set regEx = New RegExp
| > regEx.IgnoreCase = True
| > varBrowseSong = regEx.Replace("'","'")
| > Response.Write varBrowseSong
| > Response.End
~8^) Pat Wong (ICQ #61070813)
http://www.napathon.com/
-------------------------------------------------------------------
"In the interests of cutting costs, the light at
the end of the tunnel has been switched off..."
-------------------------------------------------------------------
Message #4 by "Ian: Future Proof Web Dev" <lists@f...> on Fri, 29 Nov 2002 19:06:09 -0000
|
|
Hi
I don't really understand what you're asking.
What do you mean when you say..."my browse is starting at the wrong place in
the database"
I would expect that the records pulled from the database are defined by your
SQL statement.
sorry
ian
----- Original Message -----
From: "Pat Wong" <vinyl-junkie@n...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, November 29, 2002 5:46 PM
Subject: [asp_databases] Re: Replace Method Question
> Thanks! That worked like a charm. All of the examples that I looked at
only had two arguments
> in the Replace method (maybe I was looking at the wrong thing?).
>
> Next question: Given that the string is now replaced with something that
won't cause an error,
> my browse is starting at the wrong place in the database. Any ideas why or
what I can do to get
> around it? I really need to solve this, as I'll be adding an exact match
search to the page,
> too. TIA
>
> Here's the page in case that helps:
>
>
http://www.napathon.com/MusicDBSearch.asp?BrowseSong=Don%27t+Go+Breakin%27+M
y+Heart&page
>
> ----- Original Message -----
> From: "Ian: Future Proof Web Dev" <lists@f...>
> To: "ASP Databases" <asp_databases@p...>
> Sent: Friday, November 29, 2002 9:11 AM
> Subject: [asp_databases] Re: Replace Method Question
>
>
> | try:
> |
> | varBrowseSong = "Don't Go Breakin' My Heart"
> | varBrowseSong = Replace(varBrowseSong,"'","'")
> |
> | hth
> | ian
> |
> | ----- Original Message -----
> | From: "Pat Wong" <vinyl-junkie@n...>
> | To: "ASP Databases" <asp_databases@p...>
> | Sent: Friday, November 29, 2002 5:09 PM
> | Subject: [asp_databases] Replace Method Question
> |
> |
> | > I have a form where the user is allowed to enter a song title and
begin
> | browsing my database at
> | > that point. In testing this, I discovered that a song title with an
> | apostrophe in it will cause
> | > an error, so I'm trying to figure out how to replace that with
something
> | that won't do that. I
> | > came up with some convoluted code (not the Replace method, but
something
> | else) that replaces
> | > the apostrophe with "'" (sans quotes). I don't know if that's
exactly
> | how I should be doing
> | > it. If not, how?
> | >
> | > I've been following the thread where someone suggested using the
Replace
> | method. I'm trying to
> | > figure out how to do that but having a rough go of it. I came up with
> | something that
> | > unfortunately replaces the whole string with two apostrophes. Here's
the
> | relevant code. Can you
> | > tell me what I'm doing wrong?
> | >
> | > varBrowseSong = "Don't Go Breakin' My Heart"
> | > Set regEx = New RegExp
> | > regEx.IgnoreCase = True
> | > varBrowseSong = regEx.Replace("'","'")
> | > Response.Write varBrowseSong
> | > Response.End
>
> ~8^) Pat Wong (ICQ #61070813)
> http://www.napathon.com/
> -------------------------------------------------------------------
> "In the interests of cutting costs, the light at
> the end of the tunnel has been switched off..."
> -------------------------------------------------------------------
>
>
>
Message #5 by "Pat Wong" <vinyl-junkie@n...> on Fri, 29 Nov 2002 11:23:42 -0800
|
|
Oops! Sorry I wasn't a little clearer in my explanation. I have a form on my page where I can
enter the song I want to begin browsing the database from. I enter "Don't Go Breakin' My Heart"
(sans quotes) in the form and click the submit button. The first song that comes up on the
browse page is one called "Done For," not "Don't Go Breakin' My Heart." Why? Is it even
possible to begin browsing at the point in question?
Hope this is a little clearer than mud this time. ;o)
----- Original Message -----
From: "Ian: Future Proof Web Dev" <lists@f...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, November 29, 2002 11:06 AM
Subject: [asp_databases] Re: Replace Method Question
| Hi
| I don't really understand what you're asking.
| What do you mean when you say..."my browse is starting at the wrong place in
| the database"
| I would expect that the records pulled from the database are defined by your
| SQL statement.
|
| sorry
| ian
| ----- Original Message -----
| From: "Pat Wong" <vinyl-junkie@n...>
| To: "ASP Databases" <asp_databases@p...>
| Sent: Friday, November 29, 2002 5:46 PM
| Subject: [asp_databases] Re: Replace Method Question
|
|
| > Thanks! That worked like a charm. All of the examples that I looked at
| only had two arguments
| > in the Replace method (maybe I was looking at the wrong thing?).
| >
| > Next question: Given that the string is now replaced with something that
| won't cause an error,
| > my browse is starting at the wrong place in the database. Any ideas why or
| what I can do to get
| > around it? I really need to solve this, as I'll be adding an exact match
| search to the page,
| > too. TIA
| >
| > Here's the page in case that helps:
| >
| >
| http://www.napathon.com/MusicDBSearch.asp?BrowseSong=Don%27t+Go+Breakin%27+M
| y+Heart&page
| >
| > ----- Original Message -----
| > From: "Ian: Future Proof Web Dev" <lists@f...>
| > To: "ASP Databases" <asp_databases@p...>
| > Sent: Friday, November 29, 2002 9:11 AM
| > Subject: [asp_databases] Re: Replace Method Question
| >
| >
| > | try:
| > |
| > | varBrowseSong = "Don't Go Breakin' My Heart"
| > | varBrowseSong = Replace(varBrowseSong,"'","'")
| > |
| > | hth
| > | ian
| > |
| > | ----- Original Message -----
| > | From: "Pat Wong" <vinyl-junkie@n...>
| > | To: "ASP Databases" <asp_databases@p...>
| > | Sent: Friday, November 29, 2002 5:09 PM
| > | Subject: [asp_databases] Replace Method Question
| > |
| > |
| > | > I have a form where the user is allowed to enter a song title and
| begin
| > | browsing my database at
| > | > that point. In testing this, I discovered that a song title with an
| > | apostrophe in it will cause
| > | > an error, so I'm trying to figure out how to replace that with
| something
| > | that won't do that. I
| > | > came up with some convoluted code (not the Replace method, but
| something
| > | else) that replaces
| > | > the apostrophe with "'" (sans quotes). I don't know if that's
| exactly
| > | how I should be doing
| > | > it. If not, how?
| > | >
| > | > I've been following the thread where someone suggested using the
| Replace
| > | method. I'm trying to
| > | > figure out how to do that but having a rough go of it. I came up with
| > | something that
| > | > unfortunately replaces the whole string with two apostrophes. Here's
| the
| > | relevant code. Can you
| > | > tell me what I'm doing wrong?
| > | >
| > | > varBrowseSong = "Don't Go Breakin' My Heart"
| > | > Set regEx = New RegExp
| > | > regEx.IgnoreCase = True
| > | > varBrowseSong = regEx.Replace("'","'")
| > | > Response.Write varBrowseSong
| > | > Response.End
| >
| > ~8^) Pat Wong (ICQ #61070813)
| > http://www.napathon.com/
| > -------------------------------------------------------------------
| > "In the interests of cutting costs, the light at
| > the end of the tunnel has been switched off..."
| > -------------------------------------------------------------------
| >
| >
| >
|
|
|
Message #6 by "Ian: Future Proof Web Dev" <lists@f...> on Fri, 29 Nov 2002 19:45:00 -0000
|
|
Hi
Sounds like you are using LIKE in your SQL, As you have replaced the ' with
' in your database, the entry for Don't Go Breakin' My Heart will
actually look like Don't Go Breakin' My Heart!
So your satement is working as it is recoginising the Don and pulling all
those records back.
Perhaps what you need to do is replace all the apostrophes in your look up
statement as well, then you are comparing like with like.
So you would end up with an SQL statement something like:
strSongTitle = Request.Form("SongTitle")
strSongTitle = Replace(strSongTitle,"'","'")
"SELECT SongTitle from tblSongs WHERE SongTitle LIKE "' & strSongTitle & "'"
There will probably be an easier way, this kind of question pops up a lot
and I'm sure if you browsed the archives you would find an answer.
cheers
ian
----- Original Message -----
From: "Pat Wong" <vinyl-junkie@n...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, November 29, 2002 7:23 PM
Subject: [asp_databases] Re: Replace Method Question
> Oops! Sorry I wasn't a little clearer in my explanation. I have a form on
my page where I can
> enter the song I want to begin browsing the database from. I enter "Don't
Go Breakin' My Heart"
> (sans quotes) in the form and click the submit button. The first song that
comes up on the
> browse page is one called "Done For," not "Don't Go Breakin' My Heart."
Why? Is it even
> possible to begin browsing at the point in question?
>
> Hope this is a little clearer than mud this time. ;o)
>
> ----- Original Message -----
> From: "Ian: Future Proof Web Dev" <lists@f...>
> To: "ASP Databases" <asp_databases@p...>
> Sent: Friday, November 29, 2002 11:06 AM
> Subject: [asp_databases] Re: Replace Method Question
>
>
> | Hi
> | I don't really understand what you're asking.
> | What do you mean when you say..."my browse is starting at the wrong
place in
> | the database"
> | I would expect that the records pulled from the database are defined by
your
> | SQL statement.
> |
> | sorry
> | ian
> | ----- Original Message -----
> | From: "Pat Wong" <vinyl-junkie@n...>
> | To: "ASP Databases" <asp_databases@p...>
> | Sent: Friday, November 29, 2002 5:46 PM
> | Subject: [asp_databases] Re: Replace Method Question
> |
> |
> | > Thanks! That worked like a charm. All of the examples that I looked at
> | only had two arguments
> | > in the Replace method (maybe I was looking at the wrong thing?).
> | >
> | > Next question: Given that the string is now replaced with something
that
> | won't cause an error,
> | > my browse is starting at the wrong place in the database. Any ideas
why or
> | what I can do to get
> | > around it? I really need to solve this, as I'll be adding an exact
match
> | search to the page,
> | > too. TIA
> | >
> | > Here's the page in case that helps:
> | >
> | >
> |
http://www.napathon.com/MusicDBSearch.asp?BrowseSong=Don%27t+Go+Breakin%27+M
> | y+Heart&page
> | >
> | > ----- Original Message -----
> | > From: "Ian: Future Proof Web Dev" <lists@f...>
> | > To: "ASP Databases" <asp_databases@p...>
> | > Sent: Friday, November 29, 2002 9:11 AM
> | > Subject: [asp_databases] Re: Replace Method Question
> | >
> | >
> | > | try:
> | > |
> | > | varBrowseSong = "Don't Go Breakin' My Heart"
> | > | varBrowseSong = Replace(varBrowseSong,"'","'")
> | > |
> | > | hth
> | > | ian
> | > |
> | > | ----- Original Message -----
> | > | From: "Pat Wong" <vinyl-junkie@n...>
> | > | To: "ASP Databases" <asp_databases@p...>
> | > | Sent: Friday, November 29, 2002 5:09 PM
> | > | Subject: [asp_databases] Replace Method Question
> | > |
> | > |
> | > | > I have a form where the user is allowed to enter a song title and
> | begin
> | > | browsing my database at
> | > | > that point. In testing this, I discovered that a song title with
an
> | > | apostrophe in it will cause
> | > | > an error, so I'm trying to figure out how to replace that with
> | something
> | > | that won't do that. I
> | > | > came up with some convoluted code (not the Replace method, but
> | something
> | > | else) that replaces
> | > | > the apostrophe with "'" (sans quotes). I don't know if that's
> | exactly
> | > | how I should be doing
> | > | > it. If not, how?
> | > | >
> | > | > I've been following the thread where someone suggested using the
> | Replace
> | > | method. I'm trying to
> | > | > figure out how to do that but having a rough go of it. I came up
with
> | > | something that
> | > | > unfortunately replaces the whole string with two apostrophes.
Here's
> | the
> | > | relevant code. Can you
> | > | > tell me what I'm doing wrong?
> | > | >
> | > | > varBrowseSong = "Don't Go Breakin' My Heart"
> | > | > Set regEx = New RegExp
> | > | > regEx.IgnoreCase = True
> | > | > varBrowseSong = regEx.Replace("'","'")
> | > | > Response.Write varBrowseSong
> | > | > Response.End
> | >
> | > ~8^) Pat Wong (ICQ #61070813)
> | > http://www.napathon.com/
> | > -------------------------------------------------------------------
> | > "In the interests of cutting costs, the light at
> | > the end of the tunnel has been switched off..."
> | > -------------------------------------------------------------------
> | >
> | >
> | >
> |
> |
> |
>
>
>
Message #7 by "Pat Wong" <vinyl-junkie@n...> on Fri, 29 Nov 2002 12:32:04 -0800
|
|
I've been bouncing this question off another forum as well and finally found the answer to my
question. If each of the single quotes is replaced with two single quotes, the browse works. So
now my Replace statement looks like this:
varBrowseSong = Replace(varBrowseSong,"'","''")
----- Original Message -----
From: "Ian: Future Proof Web Dev" <lists@f...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, November 29, 2002 11:45 AM
Subject: [asp_databases] Re: Replace Method Question
| Hi
| Sounds like you are using LIKE in your SQL, As you have replaced the ' with
| ' in your database, the entry for Don't Go Breakin' My Heart will
| actually look like Don't Go Breakin' My Heart!
| So your satement is working as it is recoginising the Don and pulling all
| those records back.
| Perhaps what you need to do is replace all the apostrophes in your look up
| statement as well, then you are comparing like with like.
|
| So you would end up with an SQL statement something like:
|
| strSongTitle = Request.Form("SongTitle")
| strSongTitle = Replace(strSongTitle,"'","'")
|
| "SELECT SongTitle from tblSongs WHERE SongTitle LIKE "' & strSongTitle & "'"
|
| There will probably be an easier way, this kind of question pops up a lot
| and I'm sure if you browsed the archives you would find an answer.
|
| cheers
|
| ian
| ----- Original Message -----
| From: "Pat Wong" <vinyl-junkie@n...>
| To: "ASP Databases" <asp_databases@p...>
| Sent: Friday, November 29, 2002 7:23 PM
| Subject: [asp_databases] Re: Replace Method Question
|
|
| > Oops! Sorry I wasn't a little clearer in my explanation. I have a form on
| my page where I can
| > enter the song I want to begin browsing the database from. I enter "Don't
| Go Breakin' My Heart"
| > (sans quotes) in the form and click the submit button. The first song that
| comes up on the
| > browse page is one called "Done For," not "Don't Go Breakin' My Heart."
| Why? Is it even
| > possible to begin browsing at the point in question?
| >
| > Hope this is a little clearer than mud this time. ;o)
(snip)
~8^) Pat Wong (ICQ #61070813)
http://www.napathon.com/
-------------------------------------------------------------------
"In the interests of cutting costs, the light at
the end of the tunnel has been switched off..."
-------------------------------------------------------------------
|
|
 |