Replace

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Win XP Pro - access 2002 - vs 2002 - vb

Can someone tell me why this doesn't work?

Dim MyString as string
MyString = "Winner's"
Mystring.replace("'", " ")


I'm trying to remove any single quotes from my data, so I don't get Sql
query errors.
It doesn't really matter what values I look for, the replace seems to do
nothing .

I also tried Dim MyString as Stringbuilder and system.stringbuilder but I
just get errors Stringbuilder.
I did see this in the help, Dim MyString as Stringbuilder , but I'm unable
to replicate it?

Tony
 
Have another read of the documentation for String.Replace.

The method returns the result of the Replace operation but, in you case, you
are not retaining the result.
 
What I was really saying to him Cor, was:

Read (and re-read if necessary) and make sure you understand how the
string.Replace method works.

Show someone how to find the answer and thay will learn.
Provide them with with the answer and they won't.
 
Stephany,

I know it was not critique, however a little sample learn sometimes people
easier to fish.

:-)

Cor
 
Au contraire!

10 to 1 he copies and pastes the line you supplies and nevers thinks about
it again.
 
Stephany,
10 to 1 he copies and pastes the line you supplies and nevers thinks about
it again.
You can be right, however it has no sense to try to learn someone to fish
when he does not want to learn it. The evolution learns us that those
specimen don't exist long.

However the sample was only to renforce your text not en contraire of that.

:-)

Cor
 
Tony said:
Can someone tell me why this doesn't work?

Dim MyString as string
MyString = "Winner's"
Mystring.replace("'", " ")

'String.Replace' will /return/ the resulting string! The sample below
demonstrates the use of the 'String.Replace' method and VB.NET's
'Strings.Replace' function which can be used alternatively:

\\\
Dim Text As String = "Fred's car"
Dim Result As String = Text.Replace("'", "")
MsgBox(Result)
Result = Replace(Text, "'", "")
MsgBox(Result)
///
I'm trying to remove any single quotes from my data, so I don't get Sql
query errors.
It doesn't really matter what values I look for, the replace seems to do
nothing .

Instead of preparing the strings yourself and building the whole SQL command
string, you may want to use a parameterized command that will do the
escaping automatically:

Using Parameters with a 'DataAdapter'
I also tried Dim MyString as Stringbuilder and system.stringbuilder but I
just get errors Stringbuilder.

Add 'Imports System.Text' on top of your file.
 
I thank everyone for the help.
I didn't copy and paste.
I did the below which works just fine.

Dim QM as chr(39)
Do Until InStr(TransDescription, QM) = 0
Mid(TransDescription, InStr(TransDescription, QM), 1) = " "
Loop

But I think I will replace it with

TransDescription=Transdescription.replace("'"," ")

And I will look into the parameterized command url (hope it has examples!)

Could you imagine a world where learning by example wasn't allowed?

Thanks again
 
"Tony" <[email protected]> ha scritto nel messaggio

Can someone tell me why this doesn't work?

Dim MyString as string
MyString = "Winner's"
Mystring.replace("'", " ")


I'm trying to remove any single quotes from my data, so I don't get Sql
query errors.

for Sql statements you should *double* the quote, not remove them!

Mystring = Mystring.replace("'", "''")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top