Solved

String Parsing

Posted on 2000-03-24
13
147 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now