REPLACE double quote with ""

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

REPLACE double quote with ""

Post by sal21 »

I have this myVar="TUBO'' 25" (myVar AS string), how to replace the double single quote with "" near TUBO?

is this correct?

Replace(myVar, "'", "")

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: REPLACE douyble quote with ""

Post by Doc.AElstein »

sal21 wrote:
13 Mar 2021, 08:55
is this correct?
If you want to remove the ' ' then, yes
_.___________________________________________________________________________________________________
The Visual Basic ( VB6 , VBA ) Replace function will
( ____ , “ Replace this “ , “ With this “, __ , __ , __ , )
( ____ , “ Replace this ------------> this

this ------------> this

Replace(myVar, "'", "")
or
Replace(myVar, "''", "")
will give you
TUBO 25

Replace("TUBO'' 25", "'", "") is = TUBO 25

Replace("TUBO'' 25", "''", "") is = TUBO 25


Replace(myVar, "'", "") = Replace("TUBO'' 25", "'", "") will replace ' with empty string 2 x
"' " -------> " "
" ' " -------> " "




Replace(myVar, "''", "") = Replace("TUBO'' 25", "''", "") will replace '' with empty string 1 x
" ' ' " -------> " "



https://chennaiiq.com/developers/refere ... eplace.asp
https://www.example-code.com/vb/stringReplace.asp
Last edited by Doc.AElstein on 13 Mar 2021, 11:04, edited 1 time in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: REPLACE double quote with ""

Post by YasserKhalil »

Try

Code: Select all

Sub Test()
    Dim myVar As String
    myVar = "TUBO'' 25"
    Debug.Print Replace(myVar, "'", "", , 1)
End Sub

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: REPLACE double quote with ""

Post by Doc.AElstein »

Replace(myVar, "'", "", ,1 ) = Replace("TUBO'' 25", "'", "", ,1 ) will replace ' with empty string 1 x
"' " -------> " "


Replace("TUBO'' 25", "'", "", ,1 ) is = TUBO' 25

_.______________________________________________________________________________________________________


Or
Question - I want to replace the double single quote with a double double quote near TUBO?
Answer - Replace(myVar, "'", """") is = Replace("TUBO'' 25", "'", """") is = TUBO"" 25

This is little bit more tricky…..
For Visual basic coding
"" is empty string
"""" is a single quote "

""" does not work - error


Replace(myVar, "'", """") = Replace("TUBO'' 25", "'", """") will replace ' with " 2 x
"' " -------> " " "
" ' " -------> " " "




Replace(myVar, "'", """) error


_._______________________________________________________________________________________________________________

More examples

Code: Select all

Sub QuoteBits()
 Let myVar = Replace("TUBO'' 25", "'", ""): Debug.Print myVar    '    Answer  TUBO 25         '    --->    empty        2 x
 Let myVar = Replace("TUBO'' 25", "'", """"): Debug.Print myVar  '    Answer  TUBO"" 25       '  --->  "        2 x
 Let myVar = Replace("TUBO'' 25", "''", """"): Debug.Print myVar '   Answer      TUBO" 25    ''  --->    "      1 x
 Let myVar = Replace("TUBO'' 25", "'", """", , 1): Debug.Print myVar '  Answer    TUBO"' 25    '   --->   "      1 x
End Sub
Last edited by Doc.AElstein on 13 Mar 2021, 11:50, edited 1 time in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: REPLACE double quote with ""

Post by LisaGreen »

Hi,

Coming to this late.. but FWIW.. I tend to use a variable in this sort of thing.

Dim slDQ as string

slDQ = chr(34)

HTH
Lisa