C Programming Tutorials and advice
CProgrammingTrends News Archives About Us Feedback

Recent Articles

C++/Java Arguments Written Off
When shopping for a new vehicle (or just keeping up on the latest developments), car guys will pore over performance stats, looking closely at acceleration times, skidpad numbers, and top speeds.

Facebook's HipHop Announcement Puts C++...
About three months ago, we discussed the fact that C# and C++ had been declared a couple of Microsoft's favorite languages. Now, C++ has also gotten a sort of nod from Facebook as the social network...

C, C++ Tests Posing Real Challenge To Programmers
The tests that students must take on a routine basis are no fun, and leaving them behind is perhaps of the nicer things about becoming an adult. Still, there's no...

In C++, We Don't Write Our Bugs, We Inherit Them
Inheritance is one of the concepts on C++ that is difficult to understand and frustrating to track down bugs. Inheritance is when you create a new derived class from a base class. An example would be if you had...

C++ Creator Speaks At Stevens
Within their fields, at least, the creators of different things often achieve rock-star status. A Ford Mustang with a plaque signed by Carroll Shelby will, for example...


03.04.10



Using C++ To Clean Up Your CSS Files

By Mads Kristensen

A few weeks back i found out that the method I use to minify CSS was about 5% more efficient than the YUI Compressor. I tweeted about it and was encouraged to post the code that does the actual minification.

publicstaticstring RemoveWhiteSpaceFromStylesheets(string body)

{

  body = Regex.Replace(body, @"[a-zA-Z]+#", "#");

  body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty);

  body = Regex.Replace(body, @"\s+", " ");

  body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1");

  body = body.Replace(";}", "}");

  body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1");

 
  // Remove comments from CSS

  body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty);

   return body;

}

Go beyond Search at Search Engine
Strategies New York - Register Today

The method takes a string of CSS and returns a minified version of it. The method have been modified for demo purposes, so you might want to optimize the code yourself.

Comments

About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/
About CProgrammingTrends
A collection of articles and tutorials designed to help C and C variant programmers in their programming work. C Programming Tutorials and advice





CProgrammingTrends is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagmentNews.com





-- CProgrammingTrends is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2010 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal


archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


CProgrammingTrends Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact