Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting rid of ' in strings

Posted on 2002-04-19
6
Medium Priority
?
200 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 1200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

721 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