Re: Replace characters in String

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Excel User wrote:
Hi,

I'm trying to replace special characters in a string before inserting
into a database, but cannot this to work, could some please help.

sMyString = "blah, blah blah's +"

with sMyString
.Replace(sMyString, "+", "and")
.Replace(sMyString, "&", "and")
end with

strings are not objects so they do not have methods that can be called
using the dot-notation. VBscript has a function called replace which
accepts a string as the first argument, does the replacement and returns
a new string. Here is how it should be used:

sMyString=Replace(sMyString, "+", "and")
sMyString=Replace(sMyString, "&", "and")

--
HTH,
Bob Barrows


.



Relevant Pages

  • Re: return multiple rows from sql statement
    ... strings from input values is almost certainly a safe path to SQL ... All characters that are entered in the fields make their way into the database unaltered. ... Also, mysql_real_escape_stringwill take care of NOT altering data when inserting it, providing you don;t have any hidious mechanisms like magic quotes enabled. ... The insert of what surprisinlgly was NOT a syntax error, but a string called "mysql_insert_id" into an integer field resulted in the value zero being put in. ...
    (comp.lang.php)
  • Re: A little Rolodex [revised]
    ... including alpha sort and searching for any embedded string, ... In this application, a database is a directory, ... you may optionally provide any alternate UCASE program, ... NN -> first store NN as key length ...
    (comp.sys.hp48)
  • Re: return multiple rows from sql statement
    ... strings from input values is almost certainly a safe path to SQL ... Also, being a MySQL function, it knows what MySQL needs or uses. ... All characters that are entered in the fields make their way into the database unaltered. ... The insert of what surprisinlgly was NOT a syntax error, but a string called "mysql_insert_id" into an integer field resulted in the value zero being put in. ...
    (comp.lang.php)
  • Re: Code to delete/unlink Linked tables
    ... Public intLinkODBCTables As Variant, intLinkDB2Tables As Variant ... Public strLinkBackendDB As String, strLinkDSNname As String, strLinkLibName ... ' MsgBox "This database is in MDE format...I will delete/recreate ODBC ... Public Sub fncLinkDB2Table() ...
    (microsoft.public.access.modulesdaovba)
  • Re: Establish connection with and transferring data to Access
    ... The specific problem with your code is that you need to quote string ... Dim vConnection As New ADODB.Connection ... Experiment with the object model or check the documentation for the ... Doug's code opens and writes to an existing database. ...
    (microsoft.public.word.vba.general)