Home All Groups Group Topic Archive Search About

Regular Expressions .NET

Author
24 Oct 2006 1:59 PM
Justin Fancy
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

Author
24 Oct 2006 2:56 PM
rowe_newsgroups
You mean something like:

        Dim str As String = "C:\en\aviation\users.htm"
        str = Regex.Replace(str, "C:", "")
        str = Regex.Replace(str, "\\", "/")
        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:
Show quoteHide quote
> 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
Author
24 Oct 2006 2:59 PM
rowe_newsgroups
> 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:
Show quoteHide quote
> You mean something like:
>
>         Dim str As String = "C:\en\aviation\users.htm"
>         str = Regex.Replace(str, "C:", "")
>         str = Regex.Replace(str, "\\", "/")
>         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
Author
24 Oct 2006 10:51 PM
Jay B. Harlow
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


Show quoteHide quote
"rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message
news:1161701975.078650.193980@f16g2000cwb.googlegroups.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(str, "C:", "")
>>         str = Regex.Replace(str, "\\", "/")
>>         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
>
Author
25 Oct 2006 11:02 AM
rowe_newsgroups
Thanks for the correction Jay!

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

:-)

Thanks,

Seth Rowe


Jay B. Harlow wrote:
Show quoteHide quote
> 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_newsgroups" <rowe_em***@yahoo.com> wrote in message
> news:1161701975.078650.193980@f16g2000cwb.googlegroups.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(str, "C:", "")
> >>         str = Regex.Replace(str, "\\", "/")
> >>         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
> >
Author
24 Oct 2006 5:46 PM
Göran_Andersson
Justin Fancy wrote:
Show quoteHide quote
> 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(path, "^[A-Z]:", "")

Replacing the backslashes can be done with just a regular replace.
Author
24 Oct 2006 6:01 PM
Justin Fancy
Thanks a million people!!

J
Göran Andersson wrote:
Show quoteHide quote
> 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(path, "^[A-Z]:", "")
>
> Replacing the backslashes can be done with just a regular replace.