July 2008 Entries
Ever want to match and replace whole words with in a string? Regular expressions (System.Text.RegularExpressions) makes it a one line operation:
Regex.Replace(inputText, @"\b" + wordToReplace + @"\b", replacementText, RegexOptions.IgnoreCase);
This pattern uses "word boundries" as your delimiters for matching text.
Ahh, the power (and sometimes slight confusion) of regular expressions. This seems to work well to remove HTML from text:
string htmlstring = { some chunk o html infested text };
Regex cleanOutHtml =
new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:""(.|\n)*?""|'(.|\n)*?'|[^'"">\s]+))?)+\s*|\s*)/?>");
string onlytext = cleanOutHtml.Replace(htmlstring, "");
Weee there you have it.
Here's a general way to catch most outside exceptions in your WinForm code. Add this to your program wrapper:
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
Application.ThreadException +=
new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Of course, it is always better to handle specific cases with specific types of exceptions, but it is also nice to have a general handler for anything that escapes your exception handling.
How to Shrink Your Database Transaction Log
If you have noticed that your transaction log on your SQL Server database has grown incredibly large after a long transactional process, you can try this to shrink it back down:
DBCC SHRINKFILE(mydatabase_log, 2)
GO
BACKUP LOG mydatabase WITH TRUNCATE_ONLY
GO
DBCC SHRINKFILE(mydatabase_log, 2)
GO
Of course, you'll want to replace "mydatabase" with the name of the database you wish to shrink and "mydatabase_log" with the name of the log for that database.
The July 2008 issue of TechNet Magazine is out on the website. Check out my Utility Spotlight on Microsoft SharedView:
Microsoft SharedView
The July 2008 issue of TechNet Magazine is out on the website. Check out my IT Toolbox column here:
http://technet.microsoft.com/magazine/438b8ff5-6e55-47ff-9e05-a05233f48c8c
In this issue I covered:
Automise 2 Automate Admin Tasks
BareTailPro Monitor Logs in Realtime
Total Network Inventory Inventory your Systems
Mastering Microsoft Exchange Server 2007 (book review)