Replace " character in string

X

xla76

Can anyone help me, I'm trying to replace any double quotes in a
textbox with a different character.

mystring = Replace(TextBox.Text , " , "*")

I've tried chr(34) and """"" with no luck.

Thanks
Pete
 
J

Jaap Bos

xla76 said:
Can anyone help me, I'm trying to replace any double quotes in a
textbox with a different character.

mystring = Replace(TextBox.Text , " , "*")

I've tried chr(34) and """"" with no luck.

Thanks
Pete

Strange, something like:

TextBox1.Text = "Try to replace "" by #"

TextBox2.Text = Replace(TextBox1.Text, Chr(34), "#")



works without problems for me.



Groeten,

Jaap
 
X

xla76

Thanks Jaap,

nothing like a simple typo to throw a spanner in the works - but at
least you confirmed for me that it should work.
 
H

Herfried K. Wagner [MVP]

xla76 said:
Can anyone help me, I'm trying to replace any double quotes in a
textbox with a different character.

mystring = Replace(TextBox.Text , " , "*")

I've tried chr(34) and """"" with no luck.

Use 'ControlChars.Quote' or '""""' (a string literal containing a single
double quote character, which is escaped by placing two consecutive double
quote characters inside the VB string literal).
 
P

pvdg42

xla76 said:
Can anyone help me, I'm trying to replace any double quotes in a
textbox with a different character.

mystring = Replace(TextBox.Text , " , "*")

I've tried chr(34) and """"" with no luck.

Thanks
Pete
This works fine for me in the context of a Windows application:

Dim vale As String

vale = Replace(Textbox.Text, """", "*")

Textbox.Text = vale

If it fails for you, perhaps you could supply details such as application
type and template you're using?
 
G

Guest

I always use (or a constant derived from it) ControlChars.Quote
as it reads so much clearer

guy
 

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

Top