System.Text.RegularExpressions.Regex
-
string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:
-
string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:
-
any method, which can do the same thing, is OK.
-
string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:
mimimimilaw wrote:
if I want to cut the "page=123", how to do it?
string str = "www.abc.com?page=123&no=456"; str = str.Replace("page=123&",""); MessageBox.Show (str);
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
any method, which can do the same thing, is OK.
-
mimimimilaw wrote:
if I want to cut the "page=123", how to do it?
string str = "www.abc.com?page=123&no=456"; str = str.Replace("page=123&",""); MessageBox.Show (str);
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
This works only if page is always 123, which is probably not the case. Try this instead:
Regex.Replace("www.abc.com?page=123&no=456", @"(?<urlstart>.*\?)page=\d+&(?<urlend>.*)", @"${urlstart}${urlend}")
----- If atheism is a religion, then not collecting stamps is a hobby. -- Unknown God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
-
string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:
Try using the
Uri
class. You would probably want to do something likeUri builder = new Uri("www.abc.com?page=123&no=456");
string[] parts = builder.Query.Split('&');
string final = String.Format("{0}?{1}", builder.AbsolutePath, parts[2]);Scott.
—In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]
-
This works only if page is always 123, which is probably not the case. Try this instead:
Regex.Replace("www.abc.com?page=123&no=456", @"(?<urlstart>.*\?)page=\d+&(?<urlend>.*)", @"${urlstart}${urlend}")
----- If atheism is a religion, then not collecting stamps is a hobby. -- Unknown God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
I know.. but he doesn't ask for it.. :) anyway, thanks for your code..
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)