I used to code in C language in the past and I found the scanf function very useful.
Unfortunately, there is no equivalent in C#.
I am using using it to
I have found a better solution than using sscanf from C or some rewritten part by someone (no offence)
http://msdn.microsoft.com/en-us/library/63ew9az0.aspx have a look at this article, it explains how to make named groups to extract the wanted data from a patterned string. Beware of the little error in the article and the better version below. (the colon was not part of the group)
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string url = "http://www.contoso.com:8080/letters/readme.html";
Regex r = new Regex(@"^(?\w+)://[^/]+?(?:\d+)?/",RegexOptions.None, TimeSpan.FromMilliseconds(150));
Match m = r.Match(url);
if (m.Success)
Console.WriteLine(r.Match(url).Result("${proto}:${port}"));
}
}
// The example displays the following output:
// http::8080