Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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, """", "")
Reply With Quote
  #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


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 06:10 AM.

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