简体   繁体   中英

replace a substring from a hyperlink c#.net

Using c#.net 4.0 wondering how to replace a dynamic substring from a long string(url w/ parameters). Basically i have a row of hyperlinks when clicked should navigate to a url but part of the link should be cut off from it.

display Url

http://10.2.2.13:6060/demo/service/demoportal/thirdpartyaccess.htm?wwpage= http://10.2.2.13:6060/demo/services/gtame/summary.htm &token=e250656e73b3a058d6931d045c85b8e722be892ebec69fa4fa56aa19bbce5f53

navigate the above to below once the above url is clicked

Navigate URL

http://10.2.2.13:6060/demo/service/demoportal/thirdpartyaccess.htm?wwpage= services/gtame/summary.htm &token=e250656e73b3a058d6931d045c85b8e722be892ebec69fa4fa56aa19bbce5f53

Thanks

  string s = "http://10.2.2.13:6060/demo/service/demoportal/thirdpartyaccess.htm?wwpage=http://10.2.2.13:6060/demo/services/gtame/summary.htm&token=e250656e73b3a058d6931d045c85b8e722be892ebec69fa4fa56aa19bbce5f53";
  s = Regex.Replace(s, "(.*wwpage\\=).*/(services.*)", "$1$2");

output:

http://10.2.2.13:6060/demo/service/demoportal/thirdpartyaccess.htm?wwpage=services/gtame/summary.htm&token=e250656e73b3a058d6931d045c85b8e722be892ebec69fa4fa56aa19bbce5f53

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM