Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

String Parsing

Posted on 2000-03-24
13
151 Views
Last Modified: 2010-05-02
I'm adding a record to an access database using an sql action statement and I need to check that the new record entered doesn't contain a single quote ' if it does contain a single quote I need to insert another single quote beside it so the record is added without error.
How do I parse the string searching for a single quote and then insert another single quote beside it? Is there a function that does this?
PLEASE HELP!
Cheers,
M. Smith
0
Comment
Question by:Megan
  • 3
  • 3
  • 3
  • +2
13 Comments
 
LVL 2

Expert Comment

by:tylerd
ID: 2654967
dim p as integer
dim newstr as string


p = 1
do until p > len(sqlstr)
     if mid(sqlstr,p,1) = "'" then
        newstr = newstr & "'"
     end if
     newstr = newstr & mid(sqlstr,p,1)
loop
------------------------------------

where sqlstr is the sql statement you want to fix
0
 
LVL 2

Expert Comment

by:tylerd
ID: 2654970
tylerd changed the proposed answer to a comment
0
 
LVL 2

Accepted Solution

by:
tylerd earned 100 total points
ID: 2654971
dim p as integer
dim newstr as string


p = 1
do until p > len(sqlstr)
     if mid(sqlstr,p,1) = "'" then
        newstr = newstr & "'"
     end if
     newstr = newstr & mid(sqlstr,p,1)
     p=p+1
loop
------------------------------------

where sqlstr is the sql statement you want to fix  
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 32

Expert Comment

by:bhess1
ID: 2654978
If you are using VB6, then use the Replace function:

Replace(MyString$,"'","''")

Replaces all apostrophes with two apostrophes
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2655001
Adding to Bhess1's comment:

MyString = Replace(MyString,"'","''")

Param1 MyString = your SQL Statement
Param2 "'" = 1 single quote between 2 double quotes
Param3 "''" = 2 single quotes between 2 double quotes
0
 

Author Comment

by:Megan
ID: 2655047
Thanks to everyone. I'm going to use the replace method. :)
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2655074
In case you do not have VB6 here's a replacement for the Replace-function it works just like the one in VB6...

  Function ReplaceStr(Text As String, TextFrom As String, TextTo As String)

    Dim xStart As Long
 
    xStart = InStr(Text, TextFrom)
    Do Until (xStart = 0)
      Text = left$(Text, xStart - 1) & TextTo & Mid$(Text, xStart + Len(TextFrom))
      xStart = InStr(xStart + Len(TextTo), Text, TextFrom)
    Loop
    ReplaceStr = Text

  End Function
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2655248
Megan.. you are using the replace.. but awarding the points to the code. I think bhess1 is gonna feel a little left out.. <sigh>. If you want to change your vote, the EE community service people can help you.. <smile>. If you want to award additional points to bhess1, just leave a question with "For bhess1" in the topic. And if you don't want to do anything, thats ok to.. (just keep bhess1 away from any high precipes and / or loaded guns)... LOL.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2655291
AAA
-- aa
  |  a
  |   a
  |   a
  |   a
  |   a
  |   *bang*
  |   .
  \_*splat*__________

:)
0
 

Author Comment

by:Megan
ID: 2655313
WOW! you guys take this stuff seriously :)
I'm new at this rating answers thing (i only just joined). I didn't read fully who I was awarding the points to. SORRY bhess1!
0
 

Author Comment

by:Megan
ID: 2655321
bhess1...I have another question re vb6.
i'm posting it now. hope u can help :)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2655422
<smiling>.. its Ok Megan.. "Truth, Justice and the American Way!!!".. VB Superhero code.. <lol> and a <wink>.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2661132
*groan* *moan* It's okay... I'll be out of the hospital soon... :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 82
MsgBox 2 59
using Access 8 75
MsgBox 4 68
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question