473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Regex problem...how to change only a part of a string?

Hello

I am using Regex in my masterpage to control the html. The problem is that when the HtmlTextWriter writes links to the stylesheets, ot writes lite this:

Expand|Select|Wrap|Line Numbers
  1. <link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Core%20Styles/Band.css" />
and what I want is

Expand|Select|Wrap|Line Numbers
  1. <link rel="stylesheet" type="text/css" href="/Style%20Library/en-US/Core%20Styles/Band.css" >
What I have done is removed the / at the end.

The script I am using is this

Expand|Select|Wrap|Line Numbers
  1. <script type="text/c#" runat="server">
  2.     protected override void Render(HtmlTextWriter writer) 
  3.     {
  4.  
  5.       // extract all html
  6.       System.IO.StringWriter str = new System.IO.StringWriter(); 
  7.       HtmlTextWriter wrt = new HtmlTextWriter(str); 
  8.       // render html 
  9.      base.Render(wrt); 
  10.       wrt.Close(); 
  11.       string html = str.ToString(); 
  12.  
  13.  
  14.                 scriptRegex = new Regex("<link[^>]*/>");
  15.     scriptRegex.Replace("/","");
  16.     scriptMatches = scriptRegex.Matches(html);  
  17.     for (int i = scriptMatches.Count - 1; i >= 0; i--)
  18.     { 
  19.       html = html.Insert(scriptMatches[i].Index, ""); 
  20.     }
  21.      writer.Write(html);   
  22.     }
  23.     </script>
  24.  
I know that this dosent work. I have tried to run html.Replace("/>",">"); But it runt the entire dokument and I just want to run it on the <link> in the <head>

How do i do this?
Jul 17 '07 #1
0 945

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: BMermuys | last post by:
Hi, string test="dit is een test"; bool bMatch = Regex.IsMatch( test, "^(|)*$" ); after executing, the bMatch is false The pattern is not optimized and seems a little stupid. But for large...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
15
by: Kay Schluehr | last post by:
I have a list of strings ls = and want to create a regular expression sx from it, such that sx.match(s) yields a SRE_Match object when s starts with an s_i for one i in . There might be...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
7
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title ...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
3
by: mathieu | last post by:
I do not understand what is wrong with the following regex expression. I clearly mark that the separator in between group 3 and group 4 should contain at least 2 white space, but group 3 is...
2
by: =?Utf-8?B?TWFya19C?= | last post by:
I am trying to replace any occurance of minus-point "-." with minus-zero-point "-0." My regex: Regex repoint_num = new Regex(@"\-\."); My data: string xyz = "-.9"; My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.