[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-05-17
3
Medium Priority
?
386 Views
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>
</td>

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?

Thanks!
-Sam
0
Comment
Question by:sam85281
  • 2
3 Comments
 
LVL 11

Expert Comment

by:anyoneis
ID: 16706001
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?

David
0
 
LVL 14

Accepted Solution

by:
Shiju Sasidharan earned 2000 total points
ID: 16706575
  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>"
        MsgBox(UpdateHtmlSource(s))
    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
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 16709097
Hi Sam

   thank u for the grade :-)

Shiju
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

834 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