Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting rid of ' in strings

Posted on 2002-04-19
6
Medium Priority
?
201 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
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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

886 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