473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Replacing Double quotes with TWO Single Quotes

Hi everyone,

I need to replace all instances of a double quote(") with two single
quotes('') in a text file. I already have some replacements of strings
going on, but I tried this one, but the syntax is being read wrong.

Here is the code:

lineFile1 = sr.ReadLine

Dim sb As New System.Text.StringBuilder(lineFile1)
sb.Replace("C:", "")
sb.Replace("x:", "")
sb.Replace("wwwroot", "")
sb.Replace("\", "/")
sb.Replace("!", "1")
sb.Replace("&", "2")
sb.Replace("cs-uri-stem", "")
lineFile1 = sb.ToString()

The reason why I want to achieve this is because when I read the lines
of the text file, using SB.REPLACE(""","''") into an access database
table, it gives me an unhandled exception error:

SYNTAX ERROR: MISSING OPERATOR IN QUERY EXPRESSION

which means that the database is treating it as an sql statement, which
is not what I want. I want it to be sent o the table without any
errors. Its a big txt file, so it runs for a while, but it hangs up on
the double quotes. I don't suppose it will hang on the single quotes if
I change it?

Any suggestions??

Justin Fancy

Oct 30 '06 #1
4 7401
The problem is that via some weird VB logic, you need FOUR double
quotes to get a single double quote character, not three as you had it.
Put this in your code and try again:
Public Const strDoubleQuote As String = """" 'Via weird VB logic, this
evaluates to a single double-quote mark
sb.Replace(strDoubleQuote , "''") ' The last string is " followed
by ' followed by ' followed by " which is just two single quotes
enclosed in double quotes.
Regard,
ImageAnalyst
================================================== ========
Justin Fancy wrote:
Hi everyone,

I need to replace all instances of a double quote(") with two single
quotes('') in a text file. I already have some replacements of strings
going on, but I tried this one, but the syntax is being read wrong.

Here is the code:

lineFile1 = sr.ReadLine

Dim sb As New System.Text.StringBuilder(lineFile1)
sb.Replace("C:", "")
sb.Replace("x:", "")
sb.Replace("wwwroot", "")
sb.Replace("\", "/")
sb.Replace("!", "1")
sb.Replace("&", "2")
sb.Replace("cs-uri-stem", "")
lineFile1 = sb.ToString()

The reason why I want to achieve this is because when I read the lines
of the text file, using SB.REPLACE(""","''") into an access database
table, it gives me an unhandled exception error:

SYNTAX ERROR: MISSING OPERATOR IN QUERY EXPRESSION

which means that the database is treating it as an sql statement, which
is not what I want. I want it to be sent o the table without any
errors. Its a big txt file, so it runs for a while, but it hangs up on
the double quotes. I don't suppose it will hang on the single quotes if
I change it?

Any suggestions??

Justin Fancy
Oct 30 '06 #2
"Justin Fancy" <ju*********@gmail.comschrieb:
The reason why I want to achieve this is because when I read the lines
of the text file, using SB.REPLACE(""","''") into an access database
table, it gives me an unhandled exception error:

SYNTAX ERROR: MISSING OPERATOR IN QUERY EXPRESSION
'sb.Replace(ControlChars.Quote, "''")' or 'sb.Replace("""", "''")'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Oct 30 '06 #3
The problem is that via some weird VB logic, you need FOUR double
quotes to get a single double quote character, not three as you had it.
It's not weird at all. Quote has to have some escape sequence in most
languages otherwise the compiler couldn't parse the strings. In C (and
C#, C++ or Java ) this sequence is \". In VB it is "".

--
Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
..NET and ASP .NET code
Oct 31 '06 #4
Yes that will probably work too. I just haven't retrained my memory
yet to remember whether ControlChars.Quote is a single quote
(apostrophe) or double quote (quotation mark). Unfortunately there's
no ControlChars.Apostrophe to make it super-explicit and distinct, so
the ambiguity remains (for me at least). And the tool tip /
intelllisense on it is just a mishmash of tick marks so it's hard to
see how it's really defined. I'll try to remember from now on.
Regard,
ImageAnalyst

Herfried K. Wagner [MVP] wrote:
"Justin Fancy" <ju*********@gmail.comschrieb:
The reason why I want to achieve this is because when I read the lines
of the text file, using SB.REPLACE(""","''") into an access database
table, it gives me an unhandled exception error:

SYNTAX ERROR: MISSING OPERATOR IN QUERY EXPRESSION

'sb.Replace(ControlChars.Quote, "''")' or 'sb.Replace("""", "''")'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Oct 31 '06 #5

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

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
2
by: girish | last post by:
In my XML document, some node attributes data contains both single quot and double quote characters, such as <input msg="Hello "World", What's up"/>. The double quotes are in form of escape...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
2
by: Reporter | last post by:
I got the following example from http://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/index.html : echo '<tr><td>First name:</td><td><input type="text" name="first_name"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.