Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Remove the back slash in a TextBox

Remove the back slash in a TextBox

Scheduled Pinned Locked Moved Visual Basic
csharp
16 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bob Zagars

    Sorry for the wrong term been working long hours. Still should I re-post or can you answer my question? Bob Zagars Senior Software Engineer -- modified at 14:47 Saturday 14th January, 2006

    J Offline
    J Offline
    Joshua Quick
    wrote on last edited by
    #4

    But in your code you are doing a string search for a back slash. Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Or was this a typo too?

    B 1 Reply Last reply
    0
    • J Joshua Quick

      But in your code you are doing a string search for a back slash. Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Or was this a typo too?

      B Offline
      B Offline
      Bob Zagars
      wrote on last edited by
      #5

      Then it is back slash. A domain name is prefixed wih DOMANINAME\username. When a user is defined with Windows Authentication it uses this format listed above. The original code was correct and works but does not remove the BACK SLASH. If a user want Windows Authentication the domain name is necessary, otherwise it is the user name and a password has to be entered in another location on the form. This is not a TYPO! Bob Zagars Senior Software Engineer

      1 Reply Last reply
      0
      • B Bob Zagars

        I am writing some code in VB.NET which I parse a string to remove the domain name and back slash but the back slash remains in the TextBox. Here is the code. Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() If myStartPointer > 0 Then Me.ebLoginName.Text() = Mid(Me.ebLoginName.Text(), _ myStartPointer + 2, myLength - myStartPointer + 1) Me.mccDomain.Clear() End If Bob Zagars Senior Software Engineer

        J Offline
        J Offline
        Joshua Quick
        wrote on last edited by
        #6

        The issue is on line 3. If the first character in the string is a '\', which it likely will be with a path such as "\\Foo\Bar", then the index will be zero causing it to skip over your If condition. You should change it to >= 0, like this... If myStartPointer >= 0 Then

        B 2 Replies Last reply
        0
        • J Joshua Quick

          The issue is on line 3. If the first character in the string is a '\', which it likely will be with a path such as "\\Foo\Bar", then the index will be zero causing it to skip over your If condition. You should change it to >= 0, like this... If myStartPointer >= 0 Then

          B Offline
          B Offline
          Bob Zagars
          wrote on last edited by
          #7

          That would cause a problem if the back slash was at postion 0. This error happens even when the position is in the middle of the string. Example MYDOMAINNAME\myusername The results is from my code \myusername If I add one to the start position of the Mid() method I will get \yusername The code has nothing to do with the starting position it has to do with the removal of the back slash. Bob Zagars Senior Software Engineer

          J 1 Reply Last reply
          0
          • J Joshua Quick

            The issue is on line 3. If the first character in the string is a '\', which it likely will be with a path such as "\\Foo\Bar", then the index will be zero causing it to skip over your If condition. You should change it to >= 0, like this... If myStartPointer >= 0 Then

            B Offline
            B Offline
            Bob Zagars
            wrote on last edited by
            #8

            You are dead wrong. Here is the class String Indexof() method. "Reports the index of the first occurrence of the specified String in this instance." .... "Return Value The index position of value if that string is found, or -1 if it is not. If value is Empty, the return value is 0." I have not tested at the first position which might be position 0 or 1 but my problem is not related to this issue. Mine happens in the middle of the string. Bob Zagars Senior Software Engineer

            J 1 Reply Last reply
            0
            • B Bob Zagars

              You are dead wrong. Here is the class String Indexof() method. "Reports the index of the first occurrence of the specified String in this instance." .... "Return Value The index position of value if that string is found, or -1 if it is not. If value is Empty, the return value is 0." I have not tested at the first position which might be position 0 or 1 but my problem is not related to this issue. Mine happens in the middle of the string. Bob Zagars Senior Software Engineer

              J Offline
              J Offline
              Joshua Quick
              wrote on last edited by
              #9

              Bob Zagars wrote:

              You are dead wrong.

              I'm not wrong. Your code does fail if a back slash is found at index 0. Try this string: "\\Foo".

              B 1 Reply Last reply
              0
              • J Joshua Quick

                Bob Zagars wrote:

                You are dead wrong.

                I'm not wrong. Your code does fail if a back slash is found at index 0. Try this string: "\\Foo".

                B Offline
                B Offline
                Bob Zagars
                wrote on last edited by
                #10

                Joshua Quick wrote:

                I'm not wrong. Your code does fail if a back slash is found at index 0. Try this string: "\\Foo".

                I am sorry but my code will never have "\\" in it only DOMAINNAME\username which I am getting off the problem, If you do not have an answer that will solve my problem stop replying. Bob Zagars Senior Software Engineer

                1 Reply Last reply
                0
                • B Bob Zagars

                  That would cause a problem if the back slash was at postion 0. This error happens even when the position is in the middle of the string. Example MYDOMAINNAME\myusername The results is from my code \myusername If I add one to the start position of the Mid() method I will get \yusername The code has nothing to do with the starting position it has to do with the removal of the back slash. Bob Zagars Senior Software Engineer

                  J Offline
                  J Offline
                  Joshua Quick
                  wrote on last edited by
                  #11

                  Bob Zagars wrote:

                  That would cause a problem if the back slash was at postion 0. This error happens even when the position is in the middle of the string.

                  Your code has 2 bugs in it then. The first one I already mentioned. The second bug is with how you're extracting the substring. You are being confused by the Mid() function. Mid() is a function that was used in VB6 and only exists in VB.NET for compatibility reasons. Mid() expects 1 based indexes, which is the way indexing used to work in VB6. The .NET String class uses zero based indexes. This is why you are one character off. You should call String.Substring() instead.

                  B 1 Reply Last reply
                  0
                  • J Joshua Quick

                    Bob Zagars wrote:

                    That would cause a problem if the back slash was at postion 0. This error happens even when the position is in the middle of the string.

                    Your code has 2 bugs in it then. The first one I already mentioned. The second bug is with how you're extracting the substring. You are being confused by the Mid() function. Mid() is a function that was used in VB6 and only exists in VB.NET for compatibility reasons. Mid() expects 1 based indexes, which is the way indexing used to work in VB6. The .NET String class uses zero based indexes. This is why you are one character off. You should call String.Substring() instead.

                    B Offline
                    B Offline
                    Bob Zagars
                    wrote on last edited by
                    #12

                    Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() Dim myString As String = Me.ebLoginName.Text() If myStartPointer >= 0 Then Me.ebLoginName.Text() = myString.Substring(myStartPointer + 1) Me.mccDomain.Clear() End If Same problem can not get rid of back slash. myStartPointer is suppose to be the indexed location of the back slash. Input string MYDOMAINNAME\test Results \test Bob Zagars Senior Software Engineer

                    J 1 Reply Last reply
                    0
                    • B Bob Zagars

                      Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() Dim myString As String = Me.ebLoginName.Text() If myStartPointer >= 0 Then Me.ebLoginName.Text() = myString.Substring(myStartPointer + 1) Me.mccDomain.Clear() End If Same problem can not get rid of back slash. myStartPointer is suppose to be the indexed location of the back slash. Input string MYDOMAINNAME\test Results \test Bob Zagars Senior Software Engineer

                      J Offline
                      J Offline
                      Joshua Quick
                      wrote on last edited by
                      #13

                      Bob Zagars wrote:

                      Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() Dim myString As String = Me.ebLoginName.Text() If myStartPointer >= 0 Then Me.ebLoginName.Text() = myString.Substring(myStartPointer + 1) Me.mccDomain.Clear() End If

                      I've just ran your above code with the string "MYDOMAIN\test". It worked for me. Either the input string is not what you expected or the problem lies elsewhere in your code. In either case, I recommend that you step through your code in the debugger and keep a sharp eye on your ebLoginName.Text property.

                      B 1 Reply Last reply
                      0
                      • J Joshua Quick

                        Bob Zagars wrote:

                        Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() Dim myString As String = Me.ebLoginName.Text() If myStartPointer >= 0 Then Me.ebLoginName.Text() = myString.Substring(myStartPointer + 1) Me.mccDomain.Clear() End If

                        I've just ran your above code with the string "MYDOMAIN\test". It worked for me. Either the input string is not what you expected or the problem lies elsewhere in your code. In either case, I recommend that you step through your code in the debugger and keep a sharp eye on your ebLoginName.Text property.

                        B Offline
                        B Offline
                        Bob Zagars
                        wrote on last edited by
                        #14

                        Joshua Quick wrote:

                        Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() Dim myString As String = Me.ebLoginName.Text() If myStartPointer >= 0 Then Me.ebLoginName.Text() = myString.Substring(myStartPointer + 1) Me.mccDomain.Clear() End If I've just ran your above code with the string "MYDOMAIN\test". It worked for me. Either the input string is not what you expected or the problem lies elsewhere in your code. In either case, I recommend that you step through your code in the debugger and keep a sharp eye on your ebLoginName.Text property.

                        Okay this tells me something because I thought I was crazy and could not understand how my results kept adding a back slash. I am using a class library from Janus Systems. It is their EditBox which has to be the problem. I will submit at their web site. Thanks for your help. Bob Zagars Senior Software Engineer

                        1 Reply Last reply
                        0
                        • B Bob Zagars

                          I am writing some code in VB.NET which I parse a string to remove the domain name and back slash but the back slash remains in the TextBox. Here is the code. Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\") Dim myLength As Integer = Me.ebLoginName.TextLength() If myStartPointer > 0 Then Me.ebLoginName.Text() = Mid(Me.ebLoginName.Text(), _ myStartPointer + 2, myLength - myStartPointer + 1) Me.mccDomain.Clear() End If Bob Zagars Senior Software Engineer

                          C Offline
                          C Offline
                          CodyGen
                          wrote on last edited by
                          #15

                          you can use the Replace method of the string. newstring = strbackslash.Replace("\","")

                          D 1 Reply Last reply
                          0
                          • C CodyGen

                            you can use the Replace method of the string. newstring = strbackslash.Replace("\","")

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #16

                            Or just get the code right in the first place and forget about this little "patch". RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups