Click here to Skip to main content
16,003,637 members
Home / Discussions / C#
   

C#

 
GeneralRe: DLL and Web Service Problem Pin
Phoen2521-Aug-06 10:10
Phoen2521-Aug-06 10:10 
GeneralRe: DLL and Web Service Problem Pin
Vitaliy Tsvayer21-Aug-06 10:58
Vitaliy Tsvayer21-Aug-06 10:58 
QuestionFonts - name/filepath Pin
Gomac21-Aug-06 6:34
Gomac21-Aug-06 6:34 
AnswerRe: Fonts - name/filepath Pin
stancrm21-Aug-06 6:51
stancrm21-Aug-06 6:51 
QuestionSplitContianer. How to customize splitter Pin
Bob_Tasa21-Aug-06 6:23
Bob_Tasa21-Aug-06 6:23 
QuestionDatagridView Custom Column Events Pin
Itanium21-Aug-06 6:19
Itanium21-Aug-06 6:19 
AnswerRe: DatagridView Custom Column Events Pin
Nader Elshehabi21-Aug-06 6:26
Nader Elshehabi21-Aug-06 6:26 
QuestionRegex to fix img tags Pin
Stephen Adam21-Aug-06 6:02
Stephen Adam21-Aug-06 6:02 
Hi there,

I'm writing an XHTML site and i'm using FreeTextBox to do it, unfortunately is has a nasty habbit of breaking XHTML rules with upper case tags and removing closing slashes from image tags.

Now i've written a function which fixes allot of HTML errors which it (or the user) may create. The functionalitu i'm missing is a regex which will turn

<img src="foo" alt="foo" title="foo" anyotherattribute="anyother value" >

into

<img src="foo" alt="foo" title="foo" anyotherattribute="anyother value" />

Can anyone supply a regex replace pattern which will do this?

This is my function so far in case anyone else finds it useful.

public static string MakeHTMLValid(string strInput)
{
strInput = Regex.Replace(strInput, "<P>", "<p>");
strInput = Regex.Replace(strInput, "</P>", "</p>");
strInput = Regex.Replace(strInput, "<EM>", "<em>");
strInput = Regex.Replace(strInput, "</EM>", "</em>");
strInput = Regex.Replace(strInput, "<DIV", "<div");
strInput = Regex.Replace(strInput, "</DIV>", "</div>");
strInput = Regex.Replace(strInput, "<IMG", "<img");
strInput = Regex.Replace(strInput, "<LI", "<li");
strInput = Regex.Replace(strInput, "</LI>", "</li>");
strInput = Regex.Replace(strInput, "<H1>", "<h1>");
strInput = Regex.Replace(strInput, "</H1>", "</h1>");
strInput = Regex.Replace(strInput, "<H2", "<h2");
strInput = Regex.Replace(strInput, "</H2>", "</h2>");
strInput = Regex.Replace(strInput, "<H1 class=HeadingOne>", "<h1 class=\"HeadingOne\">");
strInput = Regex.Replace(strInput, "<P class=MsoNormal>", "<p class=\"MsoNormal\">");
strInput = Regex.Replace(strInput, "<UL", "<ul");
strInput = Regex.Replace(strInput, "</UL>", "</ul>");
strInput = Regex.Replace(strInput, "<BR>", "<BR />");
strInput = Regex.Replace(strInput, "<BR />", "<br />");
strInput = Regex.Replace(strInput, "<BR>", "<br />");
strInput = Regex.Replace(strInput, "<br>", "<br />");
strInput = Regex.Replace(strInput, "class=normalText", "class=\"normalText\"", RegexOptions.IgnoreCase);
strInput = Regex.Replace(strInput, "</A>", "</a>");
strInput = Regex.Replace(strInput, "<HR>", "<hr />",RegexOptions.IgnoreCase);
strInput = Regex.Replace(strInput, "<A ", "<a ");
strInput = Regex.Replace(strInput, "<SPAN", "<span");
strInput = Regex.Replace(strInput, "</SPAN>", "</span>");
return strInput;
}


"Gödel proved that any formal system that defines the primitive recursive functions must be either incomplete or inconsistent. In particular one could not prove from within the system that the system itself was consistent even though the question could be formulated within the system."
AnswerRe: Regex to fix img tags Pin
User 665821-Aug-06 6:33
User 665821-Aug-06 6:33 
GeneralRe: Regex to fix img tags Pin
Stephen Adam22-Aug-06 2:34
Stephen Adam22-Aug-06 2:34 
QuestionDeleting a directory with files and subdirectories Pin
Dan Neely21-Aug-06 5:58
Dan Neely21-Aug-06 5:58 
AnswerRe: Deleting a directory with files and subdirectories Pin
stancrm21-Aug-06 6:07
stancrm21-Aug-06 6:07 
AnswerRe: Deleting a directory with files and subdirectories Pin
Judah Gabriel Himango21-Aug-06 7:01
sponsorJudah Gabriel Himango21-Aug-06 7:01 
QuestionPassword saving. Pin
orentuil21-Aug-06 5:54
orentuil21-Aug-06 5:54 
AnswerRe: Password saving. Pin
stancrm21-Aug-06 6:07
stancrm21-Aug-06 6:07 
QuestionApplication Running Setup Pin
orentuil21-Aug-06 5:52
orentuil21-Aug-06 5:52 
AnswerRe: Application Running Setup Pin
mav.northwind21-Aug-06 6:54
mav.northwind21-Aug-06 6:54 
QuestionAnimated gif in DataGridView Pin
e_LA21-Aug-06 4:20
e_LA21-Aug-06 4:20 
Questioncode for finding the square root of a number? Pin
diddy3421-Aug-06 4:18
diddy3421-Aug-06 4:18 
AnswerRe: code for finding the square root of a number? Pin
Judah Gabriel Himango21-Aug-06 4:27
sponsorJudah Gabriel Himango21-Aug-06 4:27 
GeneralRe: code for finding the square root of a number? Pin
diddy3421-Aug-06 4:28
diddy3421-Aug-06 4:28 
AnswerRe: code for finding the square root of a number? Pin
ToddHileHoffer21-Aug-06 4:30
ToddHileHoffer21-Aug-06 4:30 
QuestionHow to abort from closing an app. Pin
Anthony Mushrow21-Aug-06 4:00
professionalAnthony Mushrow21-Aug-06 4:00 
AnswerRe: How to abort from closing an app. Pin
Judah Gabriel Himango21-Aug-06 4:26
sponsorJudah Gabriel Himango21-Aug-06 4:26 
GeneralRe: How to abort from closing an app. Pin
Anthony Mushrow21-Aug-06 5:16
professionalAnthony Mushrow21-Aug-06 5:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.