Need a regular expression to search/repl html string from datagrid

Posted on 2006-05-17
Last Modified: 2008-01-09
I have a table rendered from a datagrid

The empty cells have a span in them like this:

<td nowrap="nowrap">
<span id="dgOrders__ctl5_Label2"></span>

The id is different in each cell

IE requires something to be in the cell to render the borders properly so I need a way to search and add an: &nbsp; into that empty span if it's empty.

Any Help?

Question by:sam85281
    LVL 11

    Expert Comment

    Can you give us a sample table? It is easy enough to parse the specific string. For example, this regex:
    "(<td nowrap="nowrap">\s*<span id=")(\w*)("></span>\s*</td>)" breaks up your target into three strings, which you can concatenate together along with the &npsp;.

    But, the hard part is filtering out everything else to get to these sequences.

    I wonder if XSLT wouldn't be a better way to go about this?

    Maybe this should be posted in a XML TA?

    LVL 14

    Accepted Solution

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim s As String
            s = "<td nowrap=""nowrap""><span id=""dgOrders__ctl5_Label2""></span></td>"
        End Sub

        Private Function UpdateHtmlSource(ByVal HtmlData As String) As String
            Dim sPattern As String
            sPattern = "(<td[\s\S]*?>[\s\S]*?)(<span[\s\S]*?></span>[\s\S]*?)(</td>)"
            UpdateHtmlSource = Regex.Replace(HtmlData, sPattern, "$1" & "&nbsp;" & "$3", RegexOptions.IgnoreCase)
        End Function
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    Hi Sam

       thank u for the grade :-)


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now