Backslash concatenation problem in VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marina

    #1

    Backslash concatenation problem in VB.NET

    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
    marina@nogacom. com

  • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

    #2
    RE: Backslash concatenation problem in VB.NET

    Marina,

    Let's see the code you are trying.

    Kerry Moorman


    "Marina" wrote:
    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
    marina@nogacom. com
    >
    >

    Comment

    • lord.zoltar@gmail.com

      #3
      Re: Backslash concatenation problem in VB.NET

      On Feb 13, 8:55 am, "Marina" <Marina...@gmai l.comwrote:
      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
      mar...@nogacom. com
      Have you tried
      str = "\\" & variable

      or maybe
      str = Chr(92) & variable

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

      Comment

      • Martin H.

        #4
        Re: Backslash concatenation problem in VB.NET

        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(D irectory,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

        Marina wrote:
        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
        marina@nogacom. com
        >

        Comment

        • Patrice

          #5
          Re: Backslash concatenation problem in VB.NET

          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...

          ---
          Patrice

          "Marina" <MarinaGre@gmai l.coma écrit dans le message de news:
          1171374916.4356 36.54460@j27g20 00...legro ups.com...
          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
          marina@nogacom. com
          >

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Backslash concatenation problem in VB.NET

            "Marina" <MarinaGre@gmai l.comschrieb:
            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)
            ///

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

            Comment

            • Mattias Sjögren

              #7
              Re: Backslash concatenation problem in VB.NET

              >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

              --
              Mattias Sjögren [C# MVP] mattias @ mvps.org
              http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
              Please reply only to the newsgroup.

              Comment

              Working...