Replace characters in String

E

Excel User

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
 
B

Bob Barrows

Excel said:
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")
 
E

Excel User

Thanks Bob,

I was just looking for a more efficient way of using the replace function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top