Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Html clean - remove image style
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { string input= "<img alt=\"\" src=\"http://admin.joytravelonline.ro/Files/EditorFiles/Images/exotic/Snap%202017-03-04%20at%2000.31.24.png\" height=\" 219px\" width=\" 320px\" style=\"text-align: left; font-family: 'Times New Roman', serif; width: 508px; height: 300px;\" color:black; />"; string input2= "<img alt=\"\" src=\"http://admin.joytravelonline.ro/Files/EditorFiles/Images/exotic/Snap%202017-03-04%20at%2000.31.24.png\" style=\"text-align: left; font-family: 'Times New Roman', serif; width: 508px; height: 300px;\" color:black; />"; string s = CleanHtml(input2); Console.Write(s); } public static string CleanHtml(string matchText) { string imageWidth=""; string imageHeight=""; string beforeStyle=""; string afterStyle=""; string imageStyleHeight=""; string imageStyleWidth=""; string ghilimele=""; string replaceText=""; bool hasStyleHeight=false; bool hasStyleWidth=false; string beforeHeight=""; string afterHeight=""; string beforeWidth=""; string afterWidtht=""; if (matchText.ToLower().Contains("style")) { imageStyleHeight = Regex.Match(matchText, "<img.+?style=(.+?)height:(.+?);", RegexOptions.IgnoreCase).Groups[2].Value; if(!(String.IsNullOrEmpty(imageStyleHeight))) { hasStyleHeight=true; } imageStyleWidth = Regex.Match(matchText, "<img.+?style=(.+?)width:(.+?);", RegexOptions.IgnoreCase).Groups[2].Value; if(!(String.IsNullOrEmpty(imageStyleWidth))) { hasStyleWidth=true; } if(hasStyleWidth || hasStyleHeight) { beforeStyle = Regex.Match(matchText, "<img(.+?)style", RegexOptions.IgnoreCase).Groups[1].Value; afterStyle = Regex.Match(matchText, "<img(.+?)style=\"(.+?)\"(.+?)/>", RegexOptions.IgnoreCase).Groups[3].Value; ghilimele = Regex.Match(matchText, "<img.+?style=(.+?)width:(.+?);", RegexOptions.IgnoreCase).Groups[1].Value; imageWidth = Regex.Match(matchText, "<img.+?width=(.+?)(.+?)(.+?)px", RegexOptions.IgnoreCase).Groups[3].Value; imageHeight = Regex.Match(matchText, "<img.+?height=(.+?)(.+?)(.+?)px", RegexOptions.IgnoreCase).Groups[3].Value; if((!(String.IsNullOrEmpty(imageWidth)))||(!(String.IsNullOrEmpty(imageHeight)))) { if (!(String.IsNullOrEmpty(imageWidth))) { //imageWidth = Regex.Match(matchText, "<img.+?width=(.+?)(.+?)(.+?)px", RegexOptions.IgnoreCase).Groups[3].Value; matchText=matchText.Replace(imageWidth+"px",imageStyleWidth); } if (!(String.IsNullOrEmpty(imageHeight))) { //imageHeight = Regex.Match(matchText, "<img.+?height=(.+?)(.+?)(.+?)px", RegexOptions.IgnoreCase).Groups[3].Value; matchText=matchText.Replace(imageHeight+"px",imageStyleHeight); } replaceText ="<img " + beforeStyle + afterStyle + "/>"; } else { replaceText = "<img " + beforeStyle + "height=" + "\"" + imageStyleHeight + "\"" + " width=" + "\"" + imageStyleWidth + "\"" + afterStyle + "/>"; } // html = Regex.Replace(html, matchText, replaceText); } } matchText = Regex.Replace(matchText, matchText, replaceText); return matchText; } } }
run
|
edit
|
history
|
help
0
Project Euler Problem 9
HelloWorld
a
Collection_ basic datastructure brushup
SVNParse
Sort example
SHA Tester 2.1
string test
congtodien
Lat/Lon with buffer