TheSwamp
Code Red => VB(A) => Topic started by: iliekater on August 27, 2007, 02:19:32 PM
-
I wonder if it is possible to replace a caracter in a string . For example in the following string :
"d:\Program files\Folder 1\Sub folder 2"
i'd like to replace the caracter "\" with "\\" , resulting :
"d:\\Program files\\Folder 1\\Sub folder 2"
Is it possible ?
I want to do this in order to convert some paths determined by VBA , to paths that Lisp will understand (it uses \\ instead of \) .
-
yes, use Instr() to find it, add it at the positions found
-
I use REPLACE
Replace(expression, find, replace[, start[, count[, compare]]])
Public Sub Main()
Dim strNewString As String
strNewString = Replace("d:\\Program files\\Folder 1\\Sub folder 2", "\\", "\", 1)
MsgBox strNewString
End Sub
-
Use replace
Dim Path as String
Dim NewPath As String
Path = "d:\Program files\Folder 1\Sub folder 2"
NewPath = Replace (Path, "\", "\\")
NewPath will equal "d:\\Program files\\Folder 1\\Sub folder 2"
dangit .. Matt beat me to the punch ...
-
dangit .. Matt beat me to the punch ...
Woohoo!!
-
dangit .. Matt beat me to the punch ...
Woohoo!!
I need to learn to type faster ...
<edit* and I obviously need to pay closer attention to what I am doing>
-
I knew there was an easier way, I just couldn't remember REPLACE off the top of my head
-
dangit .. Matt beat me to the punch ...
Woohoo!!
I need to learn to type faster ...
<edit* and I obviously need to pay closer attention to what I am doing>
Naw, He has just been waxing on and waxing off more than you. :-D
-
Thanks alot guys . It's going to be helpful . :-)
-
What about C:\test\\\Stuff.dwg
Public Function RemoveRepetitiveBackSlashes( StrText, Optional AlternativeString as String) as String
Dim StrFind as String
Dim StrDoulblure as String
if Len (Alternative) > 0 then
StrFind = AlternativeString
else
StrFind = "\"
end if
StrDoublure = StrFind & StrFind
Do While( Len(RemoveRepetitiveSlashes ) <> Len(StrText)
RemoveRepetitiveSlashes = StrText
StrText = Replace(StrText, "\", "\\")
loop
End Function