SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace MS Word quotes from string

    Hi,

    I'm using the following function to replace quote marks from a string into a format allowing storage into an Access database:

    Code:
    public function CleanQuotes( ByVal strDirty, boolRemove )
    	strData = Replace( Replace( strDirty, Chr(147), Chr(34) ), Chr(148), Chr(34) )
    	strData = Replace( Replace( strData, Chr(146), Chr(39) ), Chr(96), Chr(39) )
    	if not CBool( boolRemove ) then
    		strData = Replace( strData, Chr(39), String( 2, Chr(39) ) )
    		strData = Replace( strData, Chr(34), Chr(39) & Chr(34) )
    	elseif CBool( boolRemove ) then
    		strData = Replace( strData, Chr(39), Chr(32) )
    		strData = Replace( strData, Chr(34), Chr(32) )
    		do while InStr( 1, strData, String( 2, Chr(32) ) ) > 0
    			strData = Replace( strData, String( 2, Chr(32) ), Chr(32) )
    		loop
    	end if
    	CleanQuotes = Trim( strData )
    end function
    However, when quote marks are copied and pasted into the string, the quotes don't get replaced - hence throw an error with the database insert script.

    Does anyone know how to prevent this?

    Thanks very much...

  2. #2
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are two types of quotes. Regular which look like this (") and fancy as I call them that look like this (). My guess is you are pasting the second type of quote in to your field. Add that in to your function like this:

    Code:
    public function CleanQuotes( ByVal strDirty, boolRemove )
    strData = Replace( Replace( strDirty, Chr(147), Chr(34) ), Chr(148), Chr(34) ) strData = Replace( Replace( strData, Chr(146), Chr(39) ), Chr(96), Chr(39) )
    strDate = Replace(strData, "", "")
    if not CBool( boolRemove ) then strData = Replace( strData, Chr(39), String( 2, Chr(39) ) ) strData = Replace( strData, Chr(34), Chr(39) & Chr(34) ) elseif CBool( boolRemove ) then strData = Replace( strData, Chr(39), Chr(32) ) strData = Replace( strData, Chr(34), Chr(32) ) do while InStr( 1, strData, String( 2, Chr(32) ) ) > 0 strData = Replace( strData, String( 2, Chr(32) ), Chr(32) ) loop end if CleanQuotes = Trim( strData ) end function
    See if that fixes your problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •