Backslash concatenation problem in VB.NET

  • Thread starter Thread starter Marina
  • Start date Start date
M

Marina

Hi,

I'm trying to concatenate: "\" & variable, where variable is some
string, but VB is making it to be "\\variable".
for example if variable is "Test", vb is making it to be "\\Test"
instead of "\Test".

I've tried almost everything.
Does anyone has an idea.

Thanks a lot, Marina
(e-mail address removed)
 
Hi,

I'm trying to concatenate: "\" & variable, where variable is some
string, but VB is making it to be "\\variable".
for example if variable is "Test", vb is making it to be "\\Test"
instead of "\Test".

I've tried almost everything.
Does anyone has an idea.

Thanks a lot, Marina
(e-mail address removed)

Have you tried
str = "\\" & variable

or maybe
str = Chr(92) & variable

....I'm not sure if Chr is still valid, though.
 
Hello Marina,

I wonder, is "variable" the result of a Strings.Mid or Strings.Right
operation? In that case it could be that you cut one character too far
to the left.

Example:

Private Sub Test()
Dim Directory As String ="C:\Windows"
Dim Variable As String
Variable = Strings.Right(Directory,8)
MsgBox("\" & Variable)
End Sub

In this example you would receive "\\Windows", because you cut the
string for "variable" with 8 instead of 7 digits. Maybe it is a similar
issue with your code?

Best regards,

Martin
 
Additionnaly to other responses and if this is for path handling you have
some methods for this in System.IO.Path.

For example "Combine" will add the separator if needed...
 
Marina said:
I'm trying to concatenate: "\" & variable, where variable is some
string, but VB is making it to be "\\variable".
for example if variable is "Test", vb is making it to be "\\Test"
instead of "\Test".

\\\
Dim s As String = "Test"
Dim t As String = "\" & s
MsgBox(t)
///
 
I'm trying to concatenate: "\" & variable, where variable is some
string, but VB is making it to be "\\variable".
for example if variable is "Test", vb is making it to be "\\Test"
instead of "\Test".

You're not viewing the string in the debugger in a C# project, are
you? In C# (and other C-style languages) \\ represents a single \
since \ is an escape character.


Mattias
 
Back
Top