Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
| Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 11th, 2005, 02:19 AM
Authorized User
Join Date: Mar 2005
Location: Pune, Maharashtra, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dadahonde Send a message via Yahoo to dadahonde
Default 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

  #2 (permalink)  
Old March 11th, 2005, 04:53 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

To remove double quotes from a string you need
s = Replace(s, """", "")
  #3 (permalink)  
Old March 11th, 2005, 05:14 AM
Authorized User
Join Date: Jun 2003
Location: Cape Town, Western Cape, South Africa.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

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
    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)
    ReplaceStr = WorkText
    End If
End Function
'//end code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex with Special Characters hugh@kmcnetwork.com VB How-To 4 December 15th, 2006 03:16 PM
querystring and special characters tulincim Classic ASP Basics 4 October 4th, 2005 06:05 PM
storing special special characters in nvarchar... ACE2084 SQL Server 2000 2 February 9th, 2005 11:45 AM
special characters lian_a Classic ASP Basics 3 June 23rd, 2004 05:16 AM

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