Home All Groups Group Topic Archive Search About

Replace " character in string

Author
19 Nov 2006 2:24 PM
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

Author
19 Nov 2006 2:44 PM
Jaap Bos
"xla76" <pete.for***@gmail.com> schreef in bericht
news:1163946251.355105.251600@j44g2000cwa.googlegroups.com...
> 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
Author
19 Nov 2006 3:04 PM
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.
Author
19 Nov 2006 3:18 PM
Herfried K. Wagner [MVP]
"xla76" <pete.for***@gmail.com> schrieb:
> 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).

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
19 Nov 2006 4:48 PM
pvdg42
"xla76" <pete.for***@gmail.com> wrote in message
news:1163946251.355105.251600@j44g2000cwa.googlegroups.com...
> 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?
Author
19 Nov 2006 6:33 PM
guy
I always use (or a constant derived from it) ControlChars.Quote
as it reads so much clearer

guy

Show quoteHide quote
"xla76" wrote:

> 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
>
>