Archive for the '.net' Category

17
Jan
12

easy xml parsing in c#

Just a simple usage example:


using System.Xml;
...
XmlDocument doc = new XmlDocument();
// loading a file
doc.Load("file.xml");

// searching for multiple nodes via XPath; this will select all  elements wherever they may be
XmlNodeList books = doc.SelectNodes("//books");

foreach(XmlNode node in books)
{
   // getting attributes; assuming <book Author="Whatever">
   XmlAttribute author = node.Attributes["Author"];
   string value = author.Value;
}

15
May
10

.net regex multiline


Enabling multiline support for regexes is done with RegexOptions.Singleline and not RegexOptions.Multiline 🙂

01
Oct
09

measuring a string using .net


Here’s how you get the width and height of a string using the .NET framework ( the example is for IronPython, but you can easily adjust this for any CLI language ) :


size = System.Windows.Forms.TextRenderer.MeasureText("measure this",font)
print size.Width
print size.Height

note that font must be the font you’re using to draw the string.

18
Jul
09

my first boo code


I wrote a small utility to filter songs from a Winamp playlist. It was pretty fun to write. You can find the solution code here.

Here’s a screenshot :list_screen

I’ve commented the code if you want to read it.




Blog Stats

  • 218,505 hits