Solved

Getting rid of ' in strings

Posted on 2002-04-19
6
198 Views
Last Modified: 2010-05-02
Hi everyone,

I have a variabel called strName and sometimes there will be an apostrofe (') in this string.
But don't want to save this '. Is there a way to get rid of these '.
So what I am looking for is a function.

Thanks
Hinke
0
Comment
Question by:hinkeltje
[X]
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
6 Comments
 
LVL 3

Accepted Solution

by:
Gunsen earned 300 total points
ID: 6953120
Replace() function in VB6

or

Sub ReplaceStr(St As String, ByVal SubSt As String, ByVal NewSt As String)
'  Replaces every occurence of SubSt in St with NewSt

  Dim I As Integer

  Do
    I = InStr(1, St, SubSt, 1)
    If I > 0 Then
      St = Left$(St, I - 1) + NewSt + Mid$(St, I + Len(SubSt))
    End If
  Loop Until I = 0
End Sub
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 6953123
you can use Replace function
For Example
strString = "'Hinke'"
strString = Replace(strString, "'", "")
MsgBox strString
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 6953129
Cut and Paste above code in VB and see the results
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:deighton
ID: 6953132
why don't you want to save it?  If they are causing sql statements to fail, then you should double up the apostrophe in the sql string.

e.g

select * from tablew where name = 'O''Brien'
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6953496
Another option, if you are saving these into a database and that is why you are trying to get rid of them, is to use the ado command object with ado parameter objects.  If you put the string into the value property of a parameter object and append it to a command object, then when you run the insert/update query through the command object, it will handle the single quote perfectly.  Actually, it handles all "problem" characters perfectly, you don't have to worry about wrapping strings in quotes or not wrapping numbers in quotes.  You don't have to worry about date formats or putting # signs around dates or anything like that.  It's all I use anymore.....

By the way, if you are getting rid of the ' in names like O'Brian, you're probably going to piss off a lot of people, if you ever decide to mailmerge out a letter with their name on it like OBrian.
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6953526
I am converting ' and " to ` and ` works fine with sql statements.

Public Function FilterString(ByVal lvsIn As String, _
                             ByVal lvlConversion As geConversion) As String
  lvsIn = Replace(lvsIn, Chr(44), " ")
  lvsIn = Replace(lvsIn, Chr(39), Chr(96))
  lvsIn = Trim$(Replace(lvsIn, Chr(34), Chr(96)))
 
  Select Case lvlConversion
    Case geConversion.awpProper
      FilterString = StrConv(lvsIn, vbProperCase)
    Case geConversion.awpLower
      FilterString = StrConv(lvsIn, vbLowerCase)
    Case geConversion.awpUpper
      FilterString = StrConv(lvsIn, vbUpperCase)
    Case geConversion.awpNone
      FilterString = lvsIn
  End Select
End Function
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

752 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