Hope this is a bug in "Replace"

  • Thread starter Thread starter Dean Slindee
  • Start date Start date
D

Dean Slindee

Private NameLastFirst as object = "Public, John Q."

NameLastFirst = Replace(LastName, "'", "''")

If NameLastFirst contains "Public, John Q." before the above Replace, it
will contain "Public" after the Replace. At least that's how it's working
in my version of VS.NET. That does not seem right to me. Am I missing
something?

Note that the replacement character(s) are *apostrophes*, not *commas*

Thanks for looking,

Dean Slindee
 
Dean Slindee said:
Private NameLastFirst as object = "Public, John Q."

NameLastFirst = Replace(LastName, "'", "''")

If NameLastFirst contains "Public, John Q." before the above Replace,
it will contain "Public" after the Replace. At least that's how it's
working in my version of VS.NET. That does not seem right to me. Am
I missing something?

Note that the replacement character(s) are *apostrophes*, not
*commas*

What is the content of variable LastName? You didn't mention this.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "Dean Slindee said:
Private NameLastFirst as object = "Public, John Q."

NameLastFirst = Replace(LastName, "'", "''")

If NameLastFirst contains "Public, John Q." before the above Replace, it
will contain "Public" after the Replace. At least that's how it's working
in my version of VS.NET. That does not seem right to me. Am I missing
something?

Note that the replacement character(s) are *apostrophes*, not *commas*

I am not able to repro that using this code on VB 2003:

\\\
Dim NameLastFirst As String = "Public, John Q."
NameLastFirst = Replace(NameLastFirst, "'", "''")
MsgBox(NameLastFirst)
///

Why do you declare 'NameLastFirst' as 'Object' and not as 'String'?

Why do you replace in 'LastName' and not in 'NameLastFirst'?

What is 'LastName'?
 
Herfried,
Congrats, you caught the error, and it is mine.
NameLastFirst = Replace(LastName, "'", "''")
should read:
NameLastFirst = Replace(NameLastName, "'", "''")
(I am running parallel name fields in preparation for a conversion, normally
would have only one set of names and this error would never come into play.)

NameLastFirst was declared as an Object because it could be null and I
wanted to preserve the null value when writing it out to the new database.

Thank you.
Dean Slindee
 
Hi Dean,
Herfried,
Congrats, you caught the error, and it is mine.
NameLastFirst = Replace(LastName, "'", "''")
should read:

Why you only congrats Herfried, while Armin made us attent on this before
Herfried?

Cor
 
* "Dean Slindee said:
Congrats, you caught the error, and it is mine.
NameLastFirst = Replace(LastName, "'", "''")
should read:
NameLastFirst = Replace(NameLastName, "'", "''")
(I am running parallel name fields in preparation for a conversion, normally
would have only one set of names and this error would never come into play.)

NameLastFirst was declared as an Object because it could be null and I
wanted to preserve the null value when writing it out to the new database.

Then don't forget to turn 'Option Strict' on...
 
I think I was ready replies from the bottom up. Congrats to Armin is in
order too!
 
Back
Top