p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   How to eliminate special characters from string (http://p2p.wrox.com/showthread.php?t=26698)

dadahonde March 11th, 2005 02:19 AM

How to eliminate special characters from string
 
Hello friends,
I am having problem in eliminating spacial characters in VB
I am having following statement to connect to sql server database:

sConnString = "Provider=SQLOLEDB;Data Source=DataSource;Initial Catalog=Database;User ID=dbUser;password=dbPass;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"

   The variables in the connection string are:
DataSource, Database, dbUser and dbPass having respective values in a file. I am reading the file and fetching the values but when I fetch them, The values come in the form of double quoted string.
Thus the double quotes terminate the connection string. and connection to dadabase fails.

Please Help if possible
Thanking You
Dadasaheb


pgtips March 11th, 2005 04:53 AM

To remove double quotes from a string you need
s = Replace(s, """", "")

Bruce March 11th, 2005 05:14 AM

You can also write a function as follows:

'//start code
'use this one for normal text issues
Function sqlFixUp(TextIn)
  'fix the string being sent to the database
  sqlFixUp = ReplaceStr(TextIn, "'", "''", 0)
End Function
'use this one for non-printable characters as well
Function JetsqlFixUp(TextIn)
  'fix the string that comes from the database
  Dim strTMP As String
  strTMP = ReplaceStr(TextIn, "'", "''", 0)
  strTMP = ReplaceStr(TextIn, "&", "&&", 0)
  JetsqlFixUp = ReplaceStr(strTMP, "|", "' & chr(124) & '", 0)
End Function

'this is a generic function that is being called by both above.
Function ReplaceStr(TextIn, ByVal SearchStr As String, ByVal Replacement As String, _
                    ByVal CompMode As Integer)

   Dim WorkText As String, Pointer As Integer
   If IsNull(TextIn) Then
    ReplaceStr = Null
   Else
    WorkText = TextIn
    Pointer = InStr(1, WorkText, SearchStr, CompMode)
    Do While Pointer > 0
      WorkText = Left(WorkText, Pointer - 1) & Replacement & _
                       Mid(WorkText, Pointer + Len(SearchStr))
         Pointer = InStr(Pointer + Len(Replacement), WorkText, _
                         SearchStr, CompMode)
    Loop
    ReplaceStr = WorkText
    End If
End Function
'//end code

Regards

Bruce


All times are GMT -4. The time now is 12:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.