Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I parse a string for " or ' ? 2

Status
Not open for further replies.

riarc

Programmer
Dec 6, 2001
44
US
I need to parse a string to remove and quotes so I can insert the string into my DB. I want to write a Public Function that I can just pass a string. How can I do this?
 
Here is your function

Public Function RemoveQuotes(ByRef strIn As String) As String
Dim i As Integer
Dim strPointer As String
Dim strOut As String

For i = 1 To Len(strIn)
strPointer = Mid(strIn, i, 1)
If strPointer = Chr$(34) Or strPointer = Chr$(39) Then
Else
strOut = strOut & strPointer
End If
Next i
RemoveQuotes = strOut
End Function
Craig, mailto:sander@cogeco.ca
"Procrastination is the art of keeping up with yesterday."
I hope my post was helpful!!!
 
And here (ineveitably) is the Regular Expressions version. You'll need to add a reference to the Microsoft VBScript Regular Expressions, then:
[tt]
Option Explicit

Public Function NoQuotes(strSource As String) As String
Dim re As RegExp

Set re = New RegExp

re.Global = True
re.Pattern = """|'"
NoQuotes = re.Replace(strSource, "")
End Function
 
It would be a lot simpler using:-

Public Function RemoveQuotes(ByRef strIn As String) As String

RemoveQuotes = Replace(strIn, Chr$(34), "")
RemoveQuotes = Replace(RemoveQuotes, Chr$(39), "")

End Function


Codefish
 
Thanks I will try them both to see what works best for my app.
 
Nice Sample CodeFish... =D Craig, mailto:sander@cogeco.ca
"Procrastination is the art of keeping up with yesterday."
I hope my post was helpful!!!
 
That worked great CodeFish. Thanks you just saved me alot of time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top