I have this myVar="TUBO'' 25" (myVar AS string), how to replace the double single quote with "" near TUBO?
is this correct?
Replace(myVar, "'", "")
REPLACE double quote with ""
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: REPLACE douyble quote with ""
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
You can find me at DocAElstein also
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: REPLACE double quote with ""
Try
Code: Select all
Sub Test()
Dim myVar As String
myVar = "TUBO'' 25"
Debug.Print Replace(myVar, "'", "", , 1)
End Sub
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: REPLACE double quote with ""
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
"' " -------> " "
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
You can find me at DocAElstein also
-
- 5StarLounger
- Posts: 964
- Joined: 08 Nov 2012, 17:54
Re: REPLACE double quote with ""
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
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