Regular Expressions .NET

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

    #1

    Regular Expressions .NET

    I am new to regular expressions with .net. I was wondering if someone
    could help me out.

    I'm looking for the lines of code that will replace C: with
    nothing(""), AND all backslashes"\" to forward slashes"/".

    Example:

    ORGINAL

    x:\en\aviation\ users.htm

    FINISHED PRODUCT

    /en/aviation/users.htm

    It would be awesome if I could hear from someone on this matter.

    Thanks!

    Justin

  • rowe_newsgroups

    #2
    Re: Regular Expressions .NET

    You mean something like:

    Dim str As String = "C:\en\aviation \users.htm"
    str = Regex.Replace(s tr, "C:", "")
    str = Regex.Replace(s tr, "\\", "/")
    MsgBox(str)

    Note, the following does the same thing:

    Dim str As String = "C:\en\aviation \users.htm"
    str.Replace("C: ", "")
    str.Replace("\\ ", "/")
    MsgBox(str)

    Thanks,

    Seth Rowe


    Justin Fancy wrote:
    I am new to regular expressions with .net. I was wondering if someone
    could help me out.
    >
    I'm looking for the lines of code that will replace C: with
    nothing(""), AND all backslashes"\" to forward slashes"/".
    >
    Example:
    >
    ORGINAL
    >
    x:\en\aviation\ users.htm
    >
    FINISHED PRODUCT
    >
    /en/aviation/users.htm
    >
    It would be awesome if I could hear from someone on this matter.
    >
    Thanks!
    >
    Justin

    Comment

    • rowe_newsgroups

      #3
      Re: Regular Expressions .NET

      Note, the following does the same thing:
      >
      Note, the following does the same thing:
      >
      Dim str As String = "C:\en\aviation \users.htm"
      str.Replace("C: ", "")
      str.Replace("\\ ", "/")
      MsgBox(str)
      Oops, change "\\" to "\" Making it:

      Dim str As String = "C:\en\aviation \users.htm"
      str.Replace("C: ", "")
      str.Replace("\" , "/")
      MsgBox(str)

      Using Regex.Replace requires using double backslashes as a backslash
      has special meaning to Regex. This cause str.Replace("\\ ", "/") to look
      for 2 backslashes instead of just one.

      Thanks,

      Seth Rowe


      rowe_newsgroups wrote:
      You mean something like:
      >
      Dim str As String = "C:\en\aviation \users.htm"
      str = Regex.Replace(s tr, "C:", "")
      str = Regex.Replace(s tr, "\\", "/")
      MsgBox(str)
      >
      Note, the following does the same thing:
      >
      Dim str As String = "C:\en\aviation \users.htm"
      str.Replace("C: ", "")
      str.Replace("\\ ", "/")
      MsgBox(str)
      >
      Thanks,
      >
      Seth Rowe
      >
      >
      Justin Fancy wrote:
      I am new to regular expressions with .net. I was wondering if someone
      could help me out.

      I'm looking for the lines of code that will replace C: with
      nothing(""), AND all backslashes"\" to forward slashes"/".

      Example:

      ORGINAL

      x:\en\aviation\ users.htm

      FINISHED PRODUCT

      /en/aviation/users.htm

      It would be awesome if I could hear from someone on this matter.

      Thanks!

      Justin

      Comment

      • Göran Andersson

        #4
        Re: Regular Expressions .NET

        Justin Fancy wrote:
        I am new to regular expressions with .net. I was wondering if someone
        could help me out.
        >
        I'm looking for the lines of code that will replace C: with
        nothing(""), AND all backslashes"\" to forward slashes"/".
        >
        Example:
        >
        ORGINAL
        >
        x:\en\aviation\ users.htm
        >
        FINISHED PRODUCT
        >
        /en/aviation/users.htm
        >
        It would be awesome if I could hear from someone on this matter.
        >
        Thanks!
        >
        Justin
        >
        Removing the drive letter can be done with a regular expression:

        path = Regex.Replace(p ath, "^[A-Z]:", "")

        Replacing the backslashes can be done with just a regular replace.

        Comment

        • Justin Fancy

          #5
          Re: Regular Expressions .NET

          Thanks a million people!!

          J
          Göran Andersson wrote:
          Justin Fancy wrote:
          I am new to regular expressions with .net. I was wondering if someone
          could help me out.

          I'm looking for the lines of code that will replace C: with
          nothing(""), AND all backslashes"\" to forward slashes"/".

          Example:

          ORGINAL

          x:\en\aviation\ users.htm

          FINISHED PRODUCT

          /en/aviation/users.htm

          It would be awesome if I could hear from someone on this matter.

          Thanks!

          Justin
          >
          Removing the drive letter can be done with a regular expression:
          >
          path = Regex.Replace(p ath, "^[A-Z]:", "")

          Replacing the backslashes can be done with just a regular replace.

          Comment

          • Jay B. Harlow

            #6
            Re: Regular Expressions .NET

            Seth,
            Try:
            Dim str As String = "C:\en\aviation \users.htm"
            str = str.Replace("C: ", "")
            str = str.Replace("\" , "/")
            MsgBox(str)
            As String.Replace is a function that returns the modifed string.

            --
            Hope this helps
            Jay B. Harlow
            ..NET Application Architect, Enthusiast, & Evangelist
            T.S. Bradley - http://www.tsbradley.net


            "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
            news:1161701975 .078650.193980@ f16g2000cwb.goo glegroups.com.. .
            >Note, the following does the same thing:
            >>
            >Note, the following does the same thing:
            >>
            > Dim str As String = "C:\en\aviation \users.htm"
            > str.Replace("C: ", "")
            > str.Replace("\\ ", "/")
            > MsgBox(str)
            >
            Oops, change "\\" to "\" Making it:
            >
            Dim str As String = "C:\en\aviation \users.htm"
            str.Replace("C: ", "")
            str.Replace("\" , "/")
            MsgBox(str)
            >
            Using Regex.Replace requires using double backslashes as a backslash
            has special meaning to Regex. This cause str.Replace("\\ ", "/") to look
            for 2 backslashes instead of just one.
            >
            Thanks,
            >
            Seth Rowe
            >
            >
            rowe_newsgroups wrote:
            >You mean something like:
            >>
            > Dim str As String = "C:\en\aviation \users.htm"
            > str = Regex.Replace(s tr, "C:", "")
            > str = Regex.Replace(s tr, "\\", "/")
            > MsgBox(str)
            >>
            >Note, the following does the same thing:
            >>
            > Dim str As String = "C:\en\aviation \users.htm"
            > str.Replace("C: ", "")
            > str.Replace("\\ ", "/")
            > MsgBox(str)
            >>
            >Thanks,
            >>
            >Seth Rowe
            >>
            >>
            >Justin Fancy wrote:
            I am new to regular expressions with .net. I was wondering if someone
            could help me out.
            >
            I'm looking for the lines of code that will replace C: with
            nothing(""), AND all backslashes"\" to forward slashes"/".
            >
            Example:
            >
            ORGINAL
            >
            x:\en\aviation\ users.htm
            >
            FINISHED PRODUCT
            >
            /en/aviation/users.htm
            >
            It would be awesome if I could hear from someone on this matter.
            >
            Thanks!
            >
            Justin
            >

            Comment

            • rowe_newsgroups

              #7
              Re: Regular Expressions .NET

              Thanks for the correction Jay!

              Perhaps I should type my responses in the ide before posting
              them.......

              :-)

              Thanks,

              Seth Rowe


              Jay B. Harlow wrote:
              Seth,
              Try:
              >
              Dim str As String = "C:\en\aviation \users.htm"
              str = str.Replace("C: ", "")
              str = str.Replace("\" , "/")
              MsgBox(str)
              >
              As String.Replace is a function that returns the modifed string.
              >
              --
              Hope this helps
              Jay B. Harlow
              .NET Application Architect, Enthusiast, & Evangelist
              T.S. Bradley - http://www.tsbradley.net
              >
              >
              "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
              news:1161701975 .078650.193980@ f16g2000cwb.goo glegroups.com.. .
              Note, the following does the same thing:
              >
              Note, the following does the same thing:
              >
              Dim str As String = "C:\en\aviation \users.htm"
              str.Replace("C: ", "")
              str.Replace("\\ ", "/")
              MsgBox(str)
              Oops, change "\\" to "\" Making it:

              Dim str As String = "C:\en\aviation \users.htm"
              str.Replace("C: ", "")
              str.Replace("\" , "/")
              MsgBox(str)

              Using Regex.Replace requires using double backslashes as a backslash
              has special meaning to Regex. This cause str.Replace("\\ ", "/") to look
              for 2 backslashes instead of just one.

              Thanks,

              Seth Rowe


              rowe_newsgroups wrote:
              You mean something like:
              >
              Dim str As String = "C:\en\aviation \users.htm"
              str = Regex.Replace(s tr, "C:", "")
              str = Regex.Replace(s tr, "\\", "/")
              MsgBox(str)
              >
              Note, the following does the same thing:
              >
              Dim str As String = "C:\en\aviation \users.htm"
              str.Replace("C: ", "")
              str.Replace("\\ ", "/")
              MsgBox(str)
              >
              Thanks,
              >
              Seth Rowe
              >
              >
              Justin Fancy wrote:
              I am new to regular expressions with .net. I was wondering if someone
              could help me out.

              I'm looking for the lines of code that will replace C: with
              nothing(""), AND all backslashes"\" to forward slashes"/".

              Example:

              ORGINAL

              x:\en\aviation\ users.htm

              FINISHED PRODUCT

              /en/aviation/users.htm

              It would be awesome if I could hear from someone on this matter.

              Thanks!

              Justin

              Comment

              Working...