Solved

String Parsing

Posted on 2000-03-24
13
148 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now