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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Replace character in string

Replace character in string

Scheduled Pinned Locked Moved Visual Basic
help
6 Posts 6 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.
  • J Offline
    J Offline
    johnjsm
    wrote on last edited by
    #1

    HI, I have a string eg. 000-000-000-000 and I want to replace the last "-" with an "_" Can anyone help me to do this. Thanks

    C P N T C 5 Replies Last reply
    0
    • J johnjsm

      HI, I have a string eg. 000-000-000-000 and I want to replace the last "-" with an "_" Can anyone help me to do this. Thanks

      C Offline
      C Offline
      Coding C
      wrote on last edited by
      #2

      hi, String.Replace('-','_') hope this works. nitin...

      1 Reply Last reply
      0
      • J johnjsm

        HI, I have a string eg. 000-000-000-000 and I want to replace the last "-" with an "_" Can anyone help me to do this. Thanks

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        Try using regular expressions like: regex.Replace( yourString, "-", "_") where regex is the regular expression and yourString is the string in question. Hope this sheds some light :)


        If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa

        1 Reply Last reply
        0
        • J johnjsm

          HI, I have a string eg. 000-000-000-000 and I want to replace the last "-" with an "_" Can anyone help me to do this. Thanks

          N Offline
          N Offline
          nlarson11
          wrote on last edited by
          #4

          Dim s As String = "000-000-000-000" Dim i As Int16 = InStrRev(s, "-") Mid(s, i, 1) = "_" MsgBox(s)

          1 Reply Last reply
          0
          • J johnjsm

            HI, I have a string eg. 000-000-000-000 and I want to replace the last "-" with an "_" Can anyone help me to do this. Thanks

            T Offline
            T Offline
            The ANZAC
            wrote on last edited by
            #5

            Will the string always be the same length, as in 4 sets of characters seperated by 3 dashes?

            Posted by The ANZAC

            1 Reply Last reply
            0
            • J johnjsm

              HI, I have a string eg. 000-000-000-000 and I want to replace the last "-" with an "_" Can anyone help me to do this. Thanks

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Is this VB.NET ? If so, then you should use the string. methods, not the ones provided.  But, any sort of replace method will replace them all.  as someone suggested, if the format is always the same, you can use an index to replace the one character that's in the same place evry time.

              Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

              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