473,799 Members | 3,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace

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.replac e("'", " ")
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.stringbu ilder 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


Nov 21 '05 #1
9 1649
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.
"Tony" <To************ @msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
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.replac e("'", " ")
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.stringbu ilder 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

Nov 21 '05 #2
Tony,

To translate Stephany's words in code.
MyString = "Winner's"

MyString = Mystring.replac e("'", " ")

Cor
Nov 21 '05 #3
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.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
Tony,

To translate Stephany's words in code.
MyString = "Winner's"

MyString = Mystring.replac e("'", " ")

Cor

Nov 21 '05 #4
Stephany,

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

:-)

Cor
Nov 21 '05 #5
Au contraire!

10 to 1 he copies and pastes the line you supplies and nevers thinks about
it again.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Ot******** *****@TK2MSFTNG P10.phx.gbl...
Stephany,

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

:-)

Cor

Nov 21 '05 #6
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
Nov 21 '05 #7
"Tony" <To************ @msn.com> schrieb:
Can someone tell me why this doesn't work?

Dim MyString as string
MyString = "Winner's"
Mystring.replac e("'", " ")
'String.Replace ' will /return/ the resulting string! The sample below
demonstrates the use of the 'String.Replace ' method and VB.NET's
'Strings.Replac e' 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'
<URL:http://msdn.microsoft. com/library/en-us/cpguide/html/cpconusingparam eterswithdataad apters.asp>
I also tried Dim MyString as Stringbuilder and system.stringbu ilder but I
just get errors Stringbuilder.


Add 'Imports System.Text' on top of your file.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8
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(TransDesc ription, QM) = 0
Mid(TransDescri ption, InStr(TransDesc ription, QM), 1) = " "
Loop

But I think I will replace it with

TransDescriptio n=Transdescript ion.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



"Cor Ligthert" <no************ @planet.nl> wrote in message
news:OU******** ******@TK2MSFTN GP10.phx.gbl...
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

Nov 21 '05 #9
"Tony" <To************ @msn.com> ha scritto nel messaggio
news:#v******** ******@TK2MSFTN GP09.phx.gbl...

Can someone tell me why this doesn't work?

Dim MyString as string
MyString = "Winner's"
Mystring.replac e("'", " ")
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.replac e("'", "''")

--
Reporting tool: http://www.neodatatype.net
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3027
by: Craig Keightley | last post by:
Can these lines of sql statements be consolidated into one sql statement (possibly using reg exps??) BEGIN CODE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Update applications Set news_article = replace(news_article, '<FONT face="Times New Roman" color=#000000 size=3>', ''); Update applications Set news_article = replace(news_article, '<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">', ''); Update...
12
8174
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to do this on the server side in the SQL area of the ASP page by writing a function (with some great...
6
5679
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? Thanks
9
9161
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new functionality of VB.NET.
4
3854
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
3
3324
by: Goran Djuranovic | last post by:
Hi all, I ran into a problem where my XMLTextReader fails on .Read() when I have "<" character in one of the attribute's values. What I am trying to do is replace illegal characters ("<", "&" , etc.) with legal stuff ("&lt;", "&amp;", etc.), before I send the XML text to a SQL Server stored procedure. Currently, I am using XMLTextReader and StringWriter to do this, here is the piece of code that fails:...
3
16926
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it with: import fileinput, string, sys fileQuery = "Text.txt" sourceText = '''SOURCE'''
6
15592
by: JackpipE | last post by:
Here is my replace query and I need to run this on every column in my table. Right now I manually enter the column name (_LANGUAGES_SPOKEN) but this is time consuming and would like to automate this process as much as possible. Update PROFILE SET LANGUAGES_SPOKEN = replace(cast(_LANGUAGES_SPOKEN as nvarchar(255)),char(13)+char(10),':') Thanks,
5
9309
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of strings. Then, I googled and found this suggestion of some JavaScript Tutorials, so I used replace with a regex with a global switch:
15
1908
by: =?Utf-8?B?TWlrZSAiWU9fQkVFIiBC?= | last post by:
I have a text file that contains about 8 to 10 text sequences that I need to replace. I want to search and replace all 8 to 10 text sequence anytime I run this script Here is what I have so far. Const ForReading = 1 Const ForWriting = 2
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.