Monday, June 24, 2019
Doing everything in wrong manner
Here is a script to replace all sizes in template project to twice smaller. It is bad idea to use regular expressions for html and it is uncommon to change text on the fly in C# but it works.
public static void Main(string[] args)
{
string path = @"email\src";
Regex sizeRegEx = new Regex("size=\".+\"");
Regex valueRegEx = new Regex(@"\d+");
foreach(string file in Directory.GetFiles(path, "*.html", SearchOption.AllDirectories))
{
string text = File.ReadAllText(file);
var aStringBuilder = new StringBuilder(text);
foreach(Match m in sizeRegEx.Matches(text))
{
Console.WriteLine(m.Value);
Match valueMath = valueRegEx.Match(m.Value);
Console.WriteLine(valueMath.Value);
aStringBuilder.Remove(m.Index + valueMath.Index, valueMath.Value.Length);
int size = int.Parse(valueRegEx.Match(m.Value).Value);
string newValue = (size / 2).ToString();
aStringBuilder.Insert(m.Index + valueMath.Index, newValue);
if(valueMath.Value.Length == 2 && newValue.Length == 1)
{
aStringBuilder.Insert(m.Index + valueMath.Index + 1, " ");
}
}
File.WriteAllText(file, aStringBuilder.ToString());
}
}
public static string DeleteLines(string input, int linesToSkip)
{
int startIndex = 0;
for (int i = 0; i < linesToSkip; ++i)
startIndex = input.IndexOf('\n', startIndex) + 1;
return input.Substring(startIndex);
}
Subscribe to:
Post Comments (Atom)
debug magazine archive
71 jounals still available on issuu with great story of netlabels time. debug_mag Publisher Publications - Issuu
-
For a cheap, obsolete environment I got a problem, fyne ui does not see my opengl. I remembered, the same problem appears for WFP, it also ...
-
This iportant option in Visual studio I started to use from 2004, in JetBrains Rider 'Always Select Opened File' option is located ...
-
71 jounals still available on issuu with great story of netlabels time. debug_mag Publisher Publications - Issuu
No comments:
Post a Comment